backdrop-filter
Definition
The backdrop-filter property in CSS is used to apply a filter effect to the area behind an element. It can be used to blur, hue-rotate, saturate, or invert the colors of the element's backdrop.
Examples
Applying a blur filter to the backdrop of an element:
.blurred-element {
backdrop-filter: blur(5px);
}
Applying a hue-rotate filter to the backdrop of an element:
.hue-rotated-element {
backdrop-filter: hue-rotate(90deg);
}
Applying a saturate filter to the backdrop of an element:
.saturated-element {
backdrop-filter: saturate(150%);
}
Applying an invert filter to the backdrop of an element:
.inverted-element {
backdrop-filter: invert(100%);
}
Values
Filter Function | Description | Parameter(s) |
---|---|---|
blur | Blurs the element's backdrop. | <length> (optional, default is 0) |
brightness | Adjusts the brightness of the element's backdrop. | <number> (optional, default is 100%) |
contrast | Adjusts the contrast of the element's backdrop. | <number> (optional, default is 100%) |
grayscale | Converts the element's backdrop to grayscale. | <number> (optional, default is 100%) |
hue-rotate | Rotates the hue of the element's backdrop. | <angle> (optional, default is 0deg) |
invert | Inverts the colors of the element's backdrop. | <number> (optional, default is 100%) |
opacity | Adjusts the opacity of the element's backdrop. | <number> (optional, default is 100%) |
saturate | Adjusts the saturation of the element's backdrop. | <number> (optional, default is 100%) |
sepia | Converts the element's backdrop to sepia. | <number> (optional, default is 100%) |
Best Practices
- Use the
backdrop-filter
property sparingly, as it can have a significant impact on performance. - Avoid using the
backdrop-filter
property on elements that are frequently updated or animated, as this can also impact performance. - Consider using the
backdrop-blend-mode
property in combination with thebackdrop-filter
property to create more complex effects. - Use the
backdrop-filter
property in combination with media queries to create responsive layouts that adapt to different screen sizes and resolutions.
Browser Compatibility
Chrome | Firefox | Safari | Internet Explorer | Microsoft Edge | Opera |
---|---|---|---|---|---|
Yes | Yes | Yes | No | Yes | Yes |