Filters: blur(), drop-shadow(), Color Filters and backdrop-filter
Image-editing effects in CSS: filter functions for blur, shape-following shadows, grayscale, brightness, contrast and hue, why order matters, SVG filters, frosted glass with backdrop-filter and the backdrop root, and filter side effects.
kvi5hnuCode Sprout team member7 min readOn this page
filter applies effects that you'd normally make in an image editor, like blur, grayscale or a color shift, to any element, not only images. The browser renders the element and its descendants, runs the result through the filters, and draws that. backdrop-filter does the same to whatever is behind an element.

The filter functions
filter takes a space-separated list of functions:
img.thumb { filter: grayscale(1); }
img.thumb:hover { filter: none; }
.disabled { filter: grayscale(1) opacity(0.6); }
.hero { filter: brightness(0.8) contrast(1.1) saturate(1.2); }
| Function | 0 gives | 1 gives | Notes |
|---|---|---|---|
blur(4px) | — | — | a length: the blur radius; 0 is no blur; no percentages |
brightness() | black | unchanged | above 1 brightens |
contrast() | flat gray | unchanged | above 1 increases contrast |
saturate() | grayscale | unchanged | above 1 makes colors more intense |
grayscale() | unchanged | fully gray | values above 1 are clamped |
sepia() | unchanged | fully sepia | clamped at 1 |
invert() | unchanged | inverted colors | 0.5 gives flat gray |
opacity() | transparent | unchanged | clamped at 1 |
hue-rotate(90deg) | — | — | rotates hues around the color wheel; 360deg is unchanged |
drop-shadow() | — | — | see below |
url(#id) | — | — | an SVG <filter> |
Numbers and percentages are interchangeable: grayscale(1) is grayscale(100%). Tested in Chrome:
grayscale(2)computed tograyscale(1).brightness(150%)computed tobrightness(1.5).blur(-1px)was invalid, leavingfilterasnone.

The last two panels confirm the table's edge cases: brightness(0) gives solid black, and invert(0.5) lands every color on the same middle gray.
drop-shadow(): shadows that follow the shape
drop-shadow(offset-x offset-y blur color) draws a shadow of the element's visible pixels, not its box. That's what you want for PNG and SVG images with transparency, icons, text, or elements shaped with clip-path:
.logo { filter: drop-shadow(0 4px 6px rgb(0 0 0 / 0.3)); }
Unlike box-shadow, it has no spread and no inset. Tested in Chrome: drop-shadow(2px 2px 3px 4px red), with a spread, was invalid. The color defaults to currentColor: a shadow without a color on green text was green. Several shadows can be chained: drop-shadow(...) drop-shadow(...).
Order matters
The functions apply in order, each to the result of the previous one. Tested in Chrome with a pixel check, on a blue box with a red offset shadow:
drop-shadow(...) opacity(0.5)made the box and shadow half-transparent together: where they overlapped, only the box's blue showed.opacity(0.5) drop-shadow(...)added the shadow to an already translucent box, so the red shadow showed through the box, giving a purple overlap.
Likewise, blur() before drop-shadow() gives a shadow of the blurred element.

On the right, the same two functions give different images: sepia applied last always produces sepia tones, whatever came before it.
SVG filters
url() references an SVG <filter>, in the same page or another file, for effects that the functions can't do, like noise, displacement, or duotone color mapping:
<svg width="0" height="0" aria-hidden="true">
<filter id="duotone">
<feColorMatrix type="matrix" values="0.6 0 0 0 0.2 0.3 0 0 0 0.1 0 0 0 0 0.4 0 0 0 1 0"/>
</filter>
</svg>
.photo { filter: url(#duotone) contrast(1.1); }
All the built-in functions are defined as SVG filter shortcuts, and they can be combined with url() in one list. If the URL doesn't point to a <filter>, the whole filter list is ignored and the element is drawn unfiltered.
Side effects of filter
Any filter other than none, even blur(0), changes how the element takes part in layout and painting:
- It creates a stacking context (article 58), so
z-indexof descendants is contained. - It becomes the containing block for
position: fixedandabsolutedescendants. Tested in Chrome: aposition: fixed; top: 0; left: 0child of an element withfilter: blur(0)was placed at the filtered element's corner, 100px from the viewport edge, not at the viewport's corner. Filtered modal wrappers and sticky headers often break this way. - Effects are clipped to a filter region around the element; blurs and shadows extend past the box but are drawn as overflow, not in layout.
filter can be animated and transitioned, between lists of the same functions. Blur is expensive, especially large radii on large areas; animating opacity or transform is cheaper, so prefer them for motion.
backdrop-filter: frosted glass
backdrop-filter applies the same functions to the content behind the element, inside its border box. The element's own content isn't affected. For it to be visible, the element's background must be at least partly transparent:
.glass {
background: rgb(255 255 255 / 0.55);
backdrop-filter: blur(12px) saturate(1.4);
border: 1px solid rgb(255 255 255 / 0.6);
}
backdrop-filter works in all browsers, unprefixed in Safari since 18.
The backdrop root
The "backdrop" isn't always the whole page. It's everything painted behind the element up to the nearest backdrop root: the root element, or an ancestor with:
- a
filterorbackdrop-filter opacitybelow 1- a
maskorclip-path - a
mix-blend-modeother thannormal will-changefor one of these
Tested in Chrome with a pixel check, using backdrop-filter: invert(1) over a black page:
- With a plain parent, the backdrop was inverted to white.
- When the parent had
opacity: 0.99, afilter, orwill-change: opacity, the child saw only its transparent parent, so it stayed black. - A parent with only a
transformdidn't block it.
If a glass panel looks unfiltered, check its ancestors for these properties.
Legibility and accessibility
Translucent glass panels can make text hard to read over busy content. Check contrast against the brightest and darkest parts of what might be behind, keep the background opaque enough, and respect user preferences:
@media (prefers-reduced-transparency: reduce) {
.glass { background: white; backdrop-filter: none; }
}
prefers-reduced-transparency is supported in Chromium only (article 76), so choose a background opacity that still works without it.
body { font: 0.8rem system-ui, sans-serif; margin: 1rem; }
.controls { display: grid; grid-template-columns: 1fr 1fr; gap: 0.2rem 0.8rem; }
label { display: flex; align-items: center; gap: 0.3rem; }
label input { inline-size: 5.5rem; }
.photo { /* a "photo" made from gradients */
margin-top: 0.5rem; block-size: 4.5rem; border-radius: 8px; display: grid; place-items: center;
background: radial-gradient(circle at 30% 35%, #ffd76a 0 12%, transparent 13%),
linear-gradient(#58a6d8, #a4d4ee 55%, #3f8f4f 56%, #2f6f3c);
font-size: 2rem; color: #fff6c9;
filter: blur(var(--blur, 0px)) grayscale(var(--gray, 0)) hue-rotate(var(--hue, 0deg)) brightness(var(--bright, 1));
}
.shapes { display: flex; gap: 2rem; margin: 0.5rem 0; }
.star { font-size: 2.2rem; line-height: 1; color: #e0a100; }
.star.box { box-shadow: 4px 4px 6px rgb(0 0 0 / 0.4); } /* the box */
.star.drop { filter: drop-shadow(4px 4px 3px rgb(0 0 0 / 0.4)); } /* the glyph */
.scene {
block-size: 5rem; border-radius: 8px; display: grid; place-items: center;
background: repeating-linear-gradient(45deg, #8a3b12 0 12px, #f4c95d 12px 24px);
}
.glass {
padding: 0.6rem 0.9rem; border-radius: 8px; font-weight: 700; color: #2a2118;
background: rgb(255 255 255 / 0.5);
backdrop-filter: blur(6px) saturate(1.3);
border: 1px solid rgb(255 255 255 / 0.7);
}
The sliders chain four filters on the gradient "photo". The first star's box-shadow follows its box, and the second's drop-shadow() follows the glyph. The glass panel keeps its text sharp while blurring the stripes behind it.
What's current
filterandbackdrop-filter: all browsers;backdrop-filterunprefixed in Safari since 18.- The backdrop root rule is implemented in Chrome; panels inside translucent or filtered ancestors don't see the page behind them.
Common questions
Why does drop-shadow() reject my fourth length?
It has no spread. Use a larger blur, or box-shadow for rectangular boxes.
Why did my fixed header stop being fixed?
An ancestor has a filter (or transform, backdrop-filter, contain: paint…), which makes it the containing block for fixed descendants.
Why doesn't backdrop-filter do anything?
The element's background is opaque, or an ancestor is a backdrop root, such as one with opacity below 1.
Is filter: opacity() the same as opacity?
Visually similar, but it's part of the filter chain, so its position in the list matters, and both can be applied at once.
Summary
filterruns the rendered element through functions likeblur(),grayscale(),brightness()andhue-rotate(), in order.drop-shadow()follows visible pixels, with no spread; its color defaults tocurrentColor.url()adds SVG filters for advanced effects.- Any filter creates a stacking context and a containing block for fixed and absolute descendants.
backdrop-filterfilters what's behind a translucent element, up to the nearest backdrop root.- Check text contrast on glass, and offer an opaque fallback.
Practice questions
Write CSS that shows thumbnails in grayscale until they're hovered or focused.
Answer
.thumb { filter: grayscale(1); transition: filter 0.2s; }
.thumb:is(:hover, :focus-visible) { filter: none; }
An icon is a PNG with a transparent background. Which gives a shadow around the icon's shape: box-shadow or filter: drop-shadow()?
Answer
filter: drop-shadow(), which uses the image's alpha channel. box-shadow follows the rectangular box.
A modal with position: fixed; inset: 0 appears inside a card instead of covering the page. The card has filter: drop-shadow(0 2px 4px #0003). Why?
Answer
A filter makes the card the containing block for fixed descendants, so inset: 0 covers the card. Move the modal outside the card (or use a top-layer <dialog>), or use box-shadow on the card instead.
Why might this glass panel show no blur?
.wrapper { opacity: 0.98; }
.wrapper .glass { background: rgb(255 255 255 / 0.4); backdrop-filter: blur(10px); }
Answer
opacity below 1 makes .wrapper a backdrop root, so .glass only sees the wrapper's own content behind it, not the page. Remove the opacity or apply it elsewhere.
Previous: Custom Counter Styles With @counter-style
Next: Blend Modes: background-blend-mode, mix-blend-mode and isolation

More in CSS Course
Quiz: CSS Delicate Details
Twenty-five questions on the edge cases that surprise experienced developers: invalid custom properties, shorthands that reset values, layer order with !important, containing blocks, margin collapsing, specificity of :is() and :where(), intrinsic minimum sizes, and more, each checked in Chrome.
Quiz: CSS Interview Questions
Thirty front-end interview questions: cascade, specificity and layers, box model and margin collapsing, stacking contexts, positioning, flexbox and grid, responsive design, custom properties, performance, accessibility, modern selectors and architecture.
Quiz: CSS Course Final Exam
Thirty questions across the whole CSS course: syntax and error handling, selectors, the cascade and layers, values and units, color, the box model, backgrounds, positioning, flexbox, grid, responsive design, typography, generated content, effects, transforms, motion and architecture.
Quiz: CSS Architecture, Tooling and Debugging (CSS Part 17)
Twenty questions on modular CSS and BEM, layering a stylesheet, design tokens and theming, pattern libraries and safe refactoring, preprocessors and build tools, the at-rules reference, and debugging common CSS problems.
Discussion
Sign in to ask a question or share what you learned.