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)"
Example
#.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;
}<div style="display: flex; gap: 16px; align-items: center;">
<img src="/collections/nextjs.png" alt="" width="48" height="48" style="filter: grayscale(1) brightness(1.6); opacity: .7;">
<img src="/collections/supabase.png" alt="" width="48" height="48" style="filter: grayscale(1) brightness(1.6); opacity: .7;">
<img src="/collections/vercel.png" alt="" width="48" height="48">
</div>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
#filter: none | <filter-function>+;Values
#- The image is unchanged.
- A blur with a 4px radius.
- Full greyscale.
- Brightens by 40%.
- Shifts all hues around the colour wheel.
multiple functions
An old photograph effect with boosted contrast.
Values in practice
#none
.demo { filter: none; }blur(4px)
.demo { filter: blur(4px); }grayscale(1)
.demo { filter: grayscale(1); }brightness(1.4)
.demo { filter: brightness(1.4); }hue-rotate(120deg)
.demo { filter: hue-rotate(120deg); }sepia(1) contrast(1.2)
.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
#- backdrop-filterApplies a filter to what is visible behind an element, for example blurring the background behind a panel.
- opacitySets the transparency of the whole element together with its contents.
- mix-blend-modeSets how an element’s colours blend with what lies beneath it.
- box-shadowAdds a shadow around an element, outside or inside.
Practise it in lessons
#Spotted a mistake or missing an example? Write to us.