CSS propertyEffects

filter

Applies graphical effects to an element: blur, brightness, contrast, greyscale and more.

Initial value
none
Inherited
No
Animatable
yes, as a list of filter functions
Applies to
all elements
JavaScript
element.style.filter = "grayscale(1)"
On this page

Example

#
CSS
.logos img {
  filter: grayscale(1) brightness(1.6);
  opacity: 0.7;
  transition: filter 0.2s, opacity 0.2s;
}

.logos img:hover {
  filter: none;
  opacity: 1;
}
Preview

Definition and usage

#

The filter property processes an element’s appearance the way graphics programs do. You have the functions blur(), brightness(), contrast(), grayscale(), sepia(), saturate(), hue-rotate(), invert(), opacity() and drop-shadow().

Functions can be combined in a single declaration, for example grayscale(1) contrast(1.2). They are applied in order, from left to right.

A filter acts on the whole element together with its children. drop-shadow() differs from box-shadow in that it follows the shape of a transparent image, such as a PNG logo, rather than the element’s rectangle.

Syntax

#
Syntax
filter: none | <filter-function>+;

Values

#

Values in practice

#

none

The image is unchanged.
.demo { filter: none; }

blur(4px)

A blur with a 4px radius.
.demo { filter: blur(4px); }

grayscale(1)

Full greyscale.
.demo { filter: grayscale(1); }

brightness(1.4)

Brightens by 40%.
.demo { filter: brightness(1.4); }

hue-rotate(120deg)

Shifts all hues around the colour wheel.
.demo { filter: hue-rotate(120deg); }

sepia(1) contrast(1.2)

An old photograph effect with boosted contrast.
.demo { filter: sepia(1) contrast(1.2); }

Browser support

#

Widely available

Works in all modern browsers, phones included. You can use it without worry.

  • Chrome
  • Edge
  • Firefox
  • Safari

Good practices

#
  • Grey partner logos that regain their colour on hover are the classic use of filter: grayscale(1).
  • To blur the background behind an element, not the element itself, use backdrop-filter.

Related entries

#

Practise it in lessons

#

Spotted a mistake or missing an example? Write to us.