Blur

Master CSS blur() for modern web UIs - Gaussian blur effects, backdrop-filter frosted glass, and dynamic JavaScript manipulation

Understanding the CSS blur() Function

The blur() CSS function applies a Gaussian blur to the input image or element before it's displayed in the document. It's part of the CSS Filter Effects module, which provides powerful graphical processing capabilities natively in the browser.

Gaussian blur works by applying a Gaussian function to each pixel, calculating a weighted average of neighboring pixels. The radius parameter defines the standard deviation of this function--essentially controlling how many pixels blend into each other. A larger value creates more pronounced blurring, while smaller values produce subtle softening effects.

This technique is essential for modern web interfaces where visual polish directly impacts user experience and perceived performance.

CSS blur() Syntax Examples
1/* No effect */2filter: blur(0);3filter: blur();4 5/* Blur with 8px radius */6filter: blur(8px);7 8/* Blur with rem units */9filter: blur(1.5rem);

Syntax and Parameters

The blur() function accepts a single radius parameter that controls the intensity of the blur effect:

  • Accepts <length> values (px, rem, em, etc.)
  • Does NOT accept percentage values
  • Defaults to 0 (no blur effect)
  • Initial value for interpolation is 0

The Filter Property

The filter property provides access to multiple filter functions including blur(), which can be combined for complex visual effects. This integration with the broader CSS filter system enables powerful creative possibilities for modern web applications.

When combining multiple filters, the order matters--each filter is applied sequentially to the result of the previous one. Understanding this function composition pattern helps create sophisticated visual effects.

FunctionPurpose
blur()Gaussian blur effect
brightness()Adjust lightness
contrast()Adjust color contrast
grayscale()Convert to grayscale
sepia()Apply sepia tone
saturate()Adjust color saturation
hue-rotate()Shift color wheel
drop-shadow()Cast shadow with blur
Combining CSS Filters
1/* Combining multiple filters */2.element {3 filter: blur(5px) grayscale(50%);4}5 6.hero-section {7 filter: blur(3px) brightness(1.2) contrast(1.1);8}

JavaScript Blur Manipulation

Dynamic blur effects can be controlled via JavaScript for interactive experiences. Using inline styles and CSS custom properties enables powerful runtime control based on user interaction, scroll position, or other application states.

This approach is particularly valuable for React and Next.js applications where state management makes dynamic visual effects straightforward to implement. When controlling blur values, you'll often use boolean logic to determine the current blur state and function calls to calculate blur values based on user interactions.

The blur value can be computed dynamically using mathematical functions that map scroll position or interaction metrics to pixel values, creating smooth transitions that respond naturally to user behavior.

JavaScript Blur Manipulation
1const element = document.querySelector('.blur-effect');2 3// Set blur dynamically4element.style.filter = 'blur(10px)';5 6// Update blur based on scroll or interaction7window.addEventListener('scroll', () => {8 const scrollPosition = window.scrollY;9 const blurValue = Math.min(scrollPosition / 10, 20);10 element.style.filter = `blur(${blurValue}px)`;11});
CSS Custom Properties for Blur
1:root {2 --blur-intensity: 0px;3}4 5.dynamic-blur {6 filter: blur(var(--blur-intensity));7 transition: filter 0.3s ease;8}

Backdrop Filter: Frosted Glass Effect

The backdrop-filter property applies blur to the area behind an element, creating the popular frosted glass effect that has become a hallmark of modern UI design. This technique allows content to remain partially visible while creating visual hierarchy and depth.

For responsive web design, backdrop-filter provides an elegant way to handle overlays, navigation bars, and modal dialogs without completely obscuring the underlying content. When combined with gradient backgrounds, backdrop-filter creates sophisticated visual effects that add depth and polish to any interface.

The frosted glass aesthetic works particularly well on semi-transparent backgrounds where maintaining visual connection to the background content enhances the user experience.

Frosted Glass Effect with backdrop-filter
1.glass-card {2 background: rgba(255, 255, 255, 0.2);3 backdrop-filter: blur(10px);4 -webkit-backdrop-filter: blur(10px);5 border: 1px solid rgba(255, 255, 255, 0.3);6 border-radius: 12px;7}8 9/* Fallback for browsers without backdrop-filter */10@supports not (backdrop-filter: blur(10px)) {11 .glass-card {12 background: rgba(255, 255, 255, 0.9);13 }14}
Modern UI Applications

Common use cases for backdrop-filter with blur

Modal Overlays

Focus attention while maintaining context behind the modal

Navigation Headers

Semi-transparent sticky headers with subtle depth

Floating Elements

Elevated elements with visual depth and hierarchy

Card Overlays

Image cards with readable text overlays

SVG Filter Alternative

For advanced blur effects or browser compatibility, SVG filters provide equivalent functionality. The <feGaussianBlur> element creates blur effects that can be referenced in CSS, offering additional control for complex scenarios.

This approach is particularly useful when you need consistent cross-browser behavior or want to apply the same blur effect across multiple elements without duplicating CSS. SVG filters also support more advanced options like controlling edge behavior through the edgeMode attribute, which can be useful for specific design requirements.

When working with SVG filters, you can create complex effects by combining blur with other SVG filter primitives for sophisticated visual treatments.

Inline SVG Blur Definition
1<svg role="none">2 <filter id="blur-effect">3 <feGaussianBlur stdDeviation="5" edgeMode="duplicate" />4 </filter>5</svg>
Using SVG Filters in CSS
1/* Using SVG filters in CSS */2.svg-blur {3 filter: url('#blur-effect');4}5 6/* External SVG file */7.external-blur {8 filter: url('filters.svg#blur-effect');9}

Performance Considerations

Blur filters can be computationally expensive, especially on large elements. Understanding the performance implications helps create smooth user experiences across all devices.

Key Performance Tips

  1. Use sparingly on large areas - Full-page blur requires significant GPU resources
  2. Prefer backdrop-filter for overlays - Often more performant than blurring entire elements
  3. Test on mobile devices - Performance varies significantly across devices
  4. Use CSS will-change judiciously - Hint browser optimization only when needed

Browser Support

The blur() function has excellent browser support, available across all modern browsers since September 2016. For production web applications, you can confidently use blur effects knowing they'll work for the vast majority of users.

Animation and Transitions

CSS filters including blur can be animated for smooth visual effects. Transitions provide simple hover effects, while keyframe animations enable continuous motion. When implemented properly, these animations enhance the user experience without impacting performance.

For interactive web experiences, animated blur effects can guide user attention, provide feedback, and create memorable visual moments. The key is using smooth transitions--consider using the tofixed method when calculating precise animation values to ensure consistent, predictable results across different devices and screen sizes.

CSS Transitions and Animations
1/* CSS Transitions */2.blur-hover {3 filter: blur(0);4 transition: filter 0.3s ease;5}6 7.blur-hover:hover {8 filter: blur(8px);9}10 11/* CSS Animations */12@keyframes blur-pulse {13 0%, 100% {14 filter: blur(0);15 }16 50% {17 filter: blur(4px);18 }19}20 21.pulsing-blur {22 animation: blur-pulse 2s ease-in-out infinite;23}

Common Use Cases

Image Loading Placeholders

Create smooth image loading experiences by starting with blur and fading to clear. This technique, used by many modern platforms, improves perceived performance and provides visual continuity during image loading.

Focus and Attention Effects

Blur can direct user attention by selectively blurring non-focused elements. This pattern is common in modal dialogs, lightboxes, and focused interaction modes.

Depth and Layering

Using different blur levels creates visual hierarchy and depth, helping users understand the relationship between layers in your interface.

Image Loading Placeholders
1.image-placeholder {2 filter: blur(20px);3 transform: scale(1.1); /* Prevent blur edge artifacts */4 transition: filter 0.5s ease-out;5}6 7.image-loaded {8 filter: blur(0);9}

Next.js and React Integration

Modern React applications can leverage blur effects for enhanced user experiences. Component-based patterns make blur effects reusable and controllable. Whether using inline styles, CSS modules, or Tailwind CSS, blur effects integrate seamlessly with React's state management.

For Next.js projects, blur effects work well with Next.js Image component for loading states and with client-side interactions for dynamic visual feedback. Using CSS custom properties together with React state creates a powerful combination for interactive blur effects that respond to user input in real-time.

React Blur Component
1import { useState } from 'react';2 3const BlurImage = ({ src, alt, blurLevel = 0 }) => {4 const [isLoaded, setIsLoaded] = useState(false);5 6 return (7 <img8 src={src}9 alt={alt}10 style={{11 filter: `blur(${isLoaded ? 0 : blurLevel}px)`,12 transition: 'filter 0.5s ease-out',13 }}14 onLoad={() => setIsLoaded(true)}15 />16 );17};

Best Practices Summary

Start with subtle values

2-8px often provides the right balance between visual effect and performance

Use consistent blur levels

Create a design system with defined blur tokens for consistency

Consider accessibility

Ensure content remains readable when applying blur effects

Test performance

Profile blur effects on target devices, especially mobile

Provide fallbacks

Use @supports for browsers without backdrop-filter support

Animate with purpose

Smooth transitions enhance UX, not distract from content

Build Modern Web Interfaces with CSS

Master CSS techniques like blur, filters, and animations to create polished, performant user experiences for your digital presence.

Sources

  1. MDN Web Docs - CSS Filter Effects Guide - Official documentation on CSS filter effects module
  2. CSS-Tricks - filter Property Almanac - Practical filter property reference with examples
  3. MDN - blur() Function Reference - Official blur() function documentation