Skip to content
Tutorials Center
My learning

Topics

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.

CSS
img {
  filter: grayscale(100%) contrast(1.2);
}

Try it

Filter functions side by side
drop-shadow follows the shape

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

CSS
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) and sepia(1) hue-rotate(90deg) give different results.
  • Stacking context and containing block. Any value other than none creates a stacking context and also becomes the containing block for position: fixed and absolute descendants, 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: hidden will cut it off.
  • Accessibility. Filters change only appearance. Do not use blur to 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.