CSS Reference ยท Filters, Masks and Shapes
The filter property
Reference for the CSS filter property: apply blur, brightness, contrast, grayscale, drop-shadow, hue-rotate and other graphical effects to any element.
The filter property applies graphical effects such as blur, color shifts and shadows to an element after it has been drawn, including its children, borders and background. It is a bit like an image-editor adjustment layer: the element renders normally, then the browser processes the finished pixels.
You can chain several filter functions in one value. They run from left to right, so the order changes the result.
img { filter: grayscale(100%) contrast(1.2); }
Try it
drop-shadow() follows the visible, non-transparent shape. A box-shadow belongs to the rectangular box, so a clipped element loses it. That is why the shadow is applied to a wrapper in the first example.
Syntax
filter: none | <filter-value-list> /* <filter-value-list> = [ <filter-function> | <url> ]+ */
- Initial value:
none - Applies to: all elements; in SVG, container elements (except
<defs>) and graphics elements - Inherited: no
- Animatable: yes (filter lists interpolate function by function)
- Computed value:
none, or the list of functions with lengths made absolute
Values
| Value | Description |
|---|---|
none |
No filter. |
blur(<length>) |
Gaussian blur with the given standard deviation, e.g. blur(4px). |
brightness(<number> | <percentage>) |
1 or 100% is unchanged; below darkens, above brightens. |
contrast(<number> | <percentage>) |
1 is unchanged; 0 is flat gray. |
grayscale(<number> | <percentage>) |
0 is unchanged, 1 is fully gray. |
sepia(<number> | <percentage>) |
1 gives a warm, old-photo tone. |
hue-rotate(<angle>) |
Rotates all hues around the color wheel. |
invert(<number> | <percentage>) |
1 inverts all colors. |
saturate(<number> | <percentage>) |
0 is gray, above 1 oversaturates. |
opacity(<number> | <percentage>) |
Like the opacity property, but as a filter step. |
drop-shadow(<offset-x> <offset-y> <blur>? <color>?) |
A shadow that follows the element's alpha shape. No spread and no inset. |
url(#id) |
References an SVG <filter> element. |
The functions are described in more detail on blur() and filter functions.
Usage notes
- Order matters.
hue-rotate(90deg) sepia(1)andsepia(1) hue-rotate(90deg)give different results. - Stacking context and containing block. Any value other than
nonecreates a stacking context and also becomes the containing block forposition: fixedandabsolutedescendants, which can break fixed elements inside a filtered parent. - Filters apply to the whole subtree, text included. Blurring a card blurs its text; to blur only what is behind an element, use
backdrop-filter. - Performance.
blur()with a large radius over a big area is expensive, especially when animated. Keep radii small and test on low-end devices; promoting a static filtered element to its own layer can help. - Clipping. A blur extends beyond the box, and ancestors with
overflow: hiddenwill cut it off. - Accessibility. Filters change only appearance. Do not use
blurto hide sensitive text: the text is still in the page and readable by assistive tech and scripts.
Browser support
Supported in all current major browsers; very old versions needed a -webkit- prefix.
Related
backdrop-filterโ filters what is behind an elementblur() and filter functionsโ the individual functionsmix-blend-modeโ blends with the backdropopacityโ plain transparency- Lesson: Filters