CSS Reference ยท Functions
Filter functions: blur(), brightness(), drop-shadow() and more
Reference for CSS filter functions: blur, brightness, contrast, drop-shadow, grayscale, hue-rotate, invert, opacity, saturate and sepia, with live examples.
Filter functions apply graphical effects to an element and everything inside it, as if it were a picture you are editing: blur it, brighten it, turn it gray. You use them as values of filter (which affects the element itself) and backdrop-filter (which affects what is painted behind it).
Several functions can be combined in a list. They are applied from left to right, so the order changes the result.
.photo { filter: grayscale(80%) contrast(1.1) blur(1px); }
Try it
Syntax
blur( <length> ) /* default 0 */ brightness( <number> | <percentage> ) /* default 1 */ contrast( <number> | <percentage> ) /* default 1 */ drop-shadow( <color>? && <length>{2,3} ) grayscale( <number> | <percentage> ) /* default 0 */ hue-rotate( <angle> ) /* default 0 */ invert( <number> | <percentage> ) /* default 0 */ opacity( <number> | <percentage> ) /* default 1 */ saturate( <number> | <percentage> ) /* default 1 */ sepia( <number> | <percentage> ) /* default 0 */
Values
| Function | Description |
|---|---|
blur(r) |
Gaussian blur; r is the standard deviation as a length (0 = none). Percentages are not allowed. |
brightness(n) |
0 is black, 1 unchanged, above 1 brighter. |
contrast(n) |
0 is flat gray, 1 unchanged, above 1 stronger contrast. |
drop-shadow(x y blur color) |
A shadow of the painted shape (including transparency). The blur radius is optional; there is no spread and no inset. |
grayscale(n) |
1 (100%) fully gray, 0 unchanged. Values above 1 are clamped. |
hue-rotate(a) |
Rotates all hues around the color wheel by an angle. |
invert(n) |
1 fully inverted colors. |
opacity(n) |
Same as the opacity property, but inside a filter list. |
saturate(n) |
0 desaturated, 1 unchanged, above 1 more vivid. |
sepia(n) |
1 fully sepia-toned. |
The filter property also accepts url(#id) to reference an SVG filter, and the keyword none.
Usage notes
- Order matters.
grayscale(1) sepia(1)differs fromsepia(1) grayscale(1), because each function works on the output of the previous one. drop-shadow()vsbox-shadow.box-shadowfollows the element's box;drop-shadow()follows the alpha shape of the whole rendered result, including transparent PNG/SVG areas, clipped shapes and text.- Stacking and cost. Any filter other than
nonecreates a stacking context and a containing block for fixed descendants. Large blurs are expensive to paint; avoid animating them on big areas. - Blur edges. Blurred elements bleed outside their box; the effect can be clipped by a parent with
overflow: hidden. - Transitions. Filter lists interpolate when both sides have the same functions in the same order; use
grayscale(0)as the start value instead ofnoneif you need smooth animation. - Not a security measure. Blurring or pixelating hidden text visually does not remove it from the page.
Browser support
Supported in all current browsers.
Related
filterbackdrop-filterbox-shadow- Lesson: Filters