Color scheme

Filters and Backdrop Filter

Shadows and gradients create depth through positioning and color transitions. Filters take a different approach: they modify the rendered pixels of an element after the browser has already painted them. A filter can blur an image, desaturate a disabled button, or add a shadow that follows the actual shape of a transparent PNG rather than its rectangular bounding box. These are post-processing effects, and they fill gaps that no combination of box-shadow and background can cover.

CSS gives you two filter properties. The filter property processes the element itself. The backdrop-filter property processes whatever sits behind the element. Both accept the same set of filter functions, but they produce very different results because they operate on different layers of the rendering pipeline.

Filter Functions

The filter property accepts one or more filter functions, applied in the order you list them. The most commonly used functions are blur(), brightness(), contrast(), grayscale(), saturate(), sepia(), hue-rotate(), invert(), opacity(), and drop-shadow(). Each takes a single value that controls intensity, and you can chain them together to build layered treatments:


        /* Single function */
        .muted {
            filter: grayscale(0.6);
        }

        /* Chained: applied left to right */
        .vintage {
            filter: sepia(0.4) contrast(1.1) brightness(0.95);
        }
    

The order matters. blur(4px) brightness(1.2) blurs first and then brightens the blurred result. Reverse the order and you brighten first, then blur the brighter pixels, which spreads light differently. The difference is subtle with small values but dramatic with large ones. The MDN reference linked in the Resources section below documents every function's syntax and value range in detail.

A common real-world use is indicating disabled or inactive states. Instead of creating separate grayscale image assets, you can desaturate and dim any element with a single declaration:


        .card--disabled {
            filter: grayscale(0.8) opacity(0.6);
            pointer-events: none;
        }
    

The element is still in the DOM and still occupies space. The filter changes how it looks, not how it behaves, which is why pointer-events: none is paired with it to prevent interaction.

drop-shadow() versus box-shadow

At first glance, drop-shadow() and box-shadow seem interchangeable. Both add shadows, and their syntax looks similar. But they work in fundamentally different ways, and the distinction matters most when you are working with transparent PNG images, SVG icons, or any element whose visible shape does not match its rectangular bounding box.

box-shadow draws a shadow around the element's CSS box. If you apply it to a transparent PNG of a tree, you get a shadow around the rectangle, not around the tree. drop-shadow() is a filter function that traces the alpha channel of the rendered pixels and draws a shadow that follows the actual visible shape: the trunk, the branches, and the leaves. This is the correct tool for adding shadows to logos, icons, stickers, cutout photos, and any image with transparency.


        /* box-shadow: shadow around the rectangle */
        .logo-box {
            box-shadow: 4px 4px 8px rgba(0, 0, 0, 0.3);
        }

        /* drop-shadow: shadow follows the actual shape */
        .logo-drop {
            filter: drop-shadow(4px 4px 8px rgba(0, 0, 0, 0.3));
        }
    

Outlining Transparent Images

A useful technique for making transparent PNG or SVG content stand out against busy backgrounds is to use drop-shadow() with zero offset and a small blur to create a glow that traces the content's shape:


        /* Soft glow outline */
        .icon-glow {
            filter: drop-shadow(0 0 2px rgba(0, 0, 0, 0.5));
        }

        /* Stacked for a thicker outline */
        .icon-thick {
            filter:
                drop-shadow(0 0 1px rgba(0, 0, 0, 0.9))
                drop-shadow(0 0 1px rgba(0, 0, 0, 0.9));
        }
    

The stacking trick works because each drop-shadow() in the chain composites on top of the previous result, building up a denser edge. The advantages are real: it works on any shape without editing the source file, it responds to CSS changes (you can swap the color for dark mode), and it is far simpler than maintaining outlines in an image editor. You can also use currentColor for the shadow color so the outline automatically follows the inherited text color when the theme changes.

The trade-offs are worth knowing. Every drop-shadow() in the chain is a separate rendering pass, so stacking three or four of them on dozens of elements at once has a real GPU cost. The outline is always slightly soft because drop-shadow() applies a Gaussian blur even at a 1px radius, so you cannot get a perfectly crisp stroke the way you could with an SVG stroke property. And because the shadow is drawn from the alpha channel, any anti-aliased or semi-transparent edge pixels in the source image will produce a slightly fuzzy outline. For a handful of icons or a hero logo, the technique works beautifully. For a grid of 50 product thumbnails, you are better off baking the outline into the assets or using SVG stroke.

drop-shadow() Does Not Support spread or inset

Unlike box-shadow, the drop-shadow() filter function does not accept a spread value or the inset keyword. If you need those features, box-shadow is the only option. This is one reason both properties exist: they serve overlapping but distinct use cases.

backdrop-filter and Frosted Glass

The backdrop-filter property applies filter functions to the area behind an element rather than to the element itself. The element needs a semi-transparent background so the filtered content behind it shows through. This is how you create frosted glass panels, blurred overlays, and softened backdrops where the foreground content stays sharp.


        .glass-panel {
            background: rgba(255, 255, 255, 0.6);
            backdrop-filter: blur(12px) saturate(1.4);
        }
    

The recipe above is the classic frosted glass formula. The blur() softens whatever sits behind the panel. The saturate(1.4) bumps color intensity slightly to compensate for the washed-out look that blur alone tends to produce. Adjust the background opacity and blur radius to taste: higher opacity hides more of the background and needs less blur, while lower opacity reveals more and needs more blur to keep foreground text legible.

In dark mode, the same technique works with a dark semi-transparent background. Since your token system already uses light-dark(), you can wire the glass panel background directly into it:


        .glass-panel {
            background: light-dark(
                rgba(255, 255, 255, 0.6),
                rgba(0, 0, 0, 0.5)
            );
            backdrop-filter: blur(12px) saturate(1.4);
        }
    

Common uses include sticky navigation bars that blur the page content scrolling underneath, modal overlays that soften the background while a dialog is open, and sidebar panels that partially reveal the main content area. The effect works best when the content behind the element has visual detail that gives the blur something meaningful to work with. A backdrop blur over a solid white background is invisible.

Stacking Context Side Effects

Any element with a filter or backdrop-filter value other than none creates a new stacking context. This is the same behavior you get from position: relative with a z-index, or from transform, or from opacity less than 1. The element and all of its children are composited as a group, which can interfere with z-index ordering if you are not expecting it.

The practical consequence is that a dropdown menu, tooltip, or popover inside a filtered parent may suddenly appear behind a sibling element that it used to sit on top of. The fix is usually to move the overlay outside the filtered container so it is not trapped in the new stacking context. If you add a filter to an element and something else on the page breaks its layering, the new stacking context is almost certainly the cause. Check for it before reaching for z-index escalation.

Performance and Reduced Motion

Filters are GPU-accelerated in modern browsers, but they are not free. Every filter function is a post-processing step that runs after painting. blur() is the most expensive because it samples neighboring pixels across the entire element, and the cost scales with both the blur radius and the element's pixel area. A 20px blur on a full-width hero image is significantly more expensive than a 4px blur on a small card.

backdrop-filter is generally more expensive than filter because the browser must composite the backdrop area, apply the filter, and then composite the foreground element on top. On lower-powered devices, a backdrop-filter: blur(20px) on a sticky header can cause visible scroll jank. Test on real hardware, not just your development machine.

If you animate a filter value (transitioning from blur(0) to blur(10px), for example), pair it with a prefers-reduced-motion check. Users who have requested reduced motion may find animated blur effects disorienting. A reasonable fallback is to skip the animation and use a solid overlay instead:


        .modal-backdrop {
            backdrop-filter: blur(12px);
            transition: backdrop-filter 0.3s ease;
        }

        @media (prefers-reduced-motion: reduce) {
            .modal-backdrop {
                backdrop-filter: none;
                background: rgba(0, 0, 0, 0.7);
                transition: none;
            }
        }
    

Guided Demos

The demos below let you see filter functions and backdrop filter in action. Use the color scheme toggle to check how each effect looks in both light and dark mode:

Filter Functions

Toggle individual filter functions on and off to see how they affect the image. Try combining several at once to see how order and combination change the result:

Filter Functions

Color scheme
Sample landscape photo for filter demo
filter: none;

Backdrop Filter versus Filter

The same blur applied two ways. On the left, filter blurs the overlay itself, making its text unreadable. On the right, backdrop-filter blurs what sits behind the overlay while the text stays sharp:

Filter vs. Backdrop Filter

Color scheme
This text is blurred

filter: blur(6px)

This text stays sharp

backdrop-filter: blur(12px)

Resources

  • MDN: filter — Full reference for every filter function with syntax, values, and browser notes
  • MDN: backdrop-filter — Reference for backdrop filter including the frosted glass pattern and stacking context behavior
  • MDN: drop-shadow() — Detailed comparison with box-shadow and usage with transparent images
  • CSS-Tricks: filter — Visual examples and practical recipes for combining filter functions
  • web.dev: Backdrop Filter — Performance considerations and progressive enhancement strategies for backdrop blur