The CSS backdrop-filter property applies graphical effects such as blur, brightness, and color changes to the area behind an element. Unlike filter, it does not apply effects to the element's own content.
- It is commonly used to create frosted-glass effects and improve text readability over backgrounds.
- The element's background must be transparent or partially transparent to reveal the filtered backdrop.
Syntax
backdrop-filter: none | filter-function;Filter Functions
| Function | Description | Example |
|---|---|---|
| blur() | Blurs the background | blur(5px) |
| brightness() | Adjusts brightness | brightness(70%) |
| contrast() | Adjusts contrast | contrast(150%) |
| drop-shadow() | Adds a shadow effect | drop-shadow(4px 4px 6px black) |
| grayscale() | Converts colors to grayscale | grayscale(100%) |
| hue-rotate() | Rotates colors around the color wheel | hue-rotate(180deg) |
| invert() | Inverts colors | invert(100%) |
| opacity() | Adjusts backdrop opacity | opacity(50%) |
| saturate() | Adjusts color saturation | saturate(150%) |
| sepia() | Applies a sepia effect | sepia(100%) |
Example:
<!DOCTYPE html>
<html>
<head>
<title>Backdrop Filter Effects</title>
<style>
body {
font-family: Arial, sans-serif;
background: #eee;
padding: 20px;
}
.container {
display: flex;
flex-wrap: wrap;
gap: 15px;
}
.box {
width: 160px;
height: 120px;
display: grid;
place-items: center;
background:
linear-gradient(45deg, #ff5722, #2196f3, #4caf50);
border-radius: 10px;
overflow: hidden;
}
.glass {
width: 100%;
padding: 15px 0;
text-align: center;
color: white;
background: rgb(255 255 255 / 20%);
}
.blur {
backdrop-filter: blur(5px);
}
.brightness {
backdrop-filter: brightness(40%);
}
.contrast {
backdrop-filter: contrast(200%);
}
.grayscale {
backdrop-filter: grayscale(100%);
}
.hue {
backdrop-filter: hue-rotate(180deg);
}
</style>
</head>
<body>
<h2>Backdrop Filter Effects</h2>
<div class="container">
<div class="box">
<div class="glass blur">Blur</div>
</div>
<div class="box">
<div class="glass brightness">Brightness</div>
</div>
<div class="box">
<div class="glass contrast">Contrast</div>
</div>
<div class="box">
<div class="glass grayscale">Grayscale</div>
</div>
<div class="box">
<div class="glass hue">Hue Rotate</div>
</div>
</div>
</body>
</html>
Global Values
| Value | Description |
|---|---|
| none | No backdrop effect (default). |
| initial | Resets the property to none. |
| inherit | Inherits the parent's computed value. |
| unset | Acts as initial because the property is not inherited. |
| revert | Reverts the property to the previous cascade origin. |
| revert-layer | Reverts the property in the current cascade layer. |
Example:
<!DOCTYPE html>
<html>
<head>
<title>Backdrop Filter Effects</title>
<style>
body {
font-family: Arial, sans-serif;
background: #eee;
padding: 20px;
}
.container {
display: flex;
flex-wrap: wrap;
gap: 15px;
}
.box {
width: 160px;
height: 120px;
display: grid;
place-items: center;
background:
linear-gradient(45deg, #ff5722, #2196f3, #4caf50);
border-radius: 10px;
overflow: hidden;
}
.glass {
width: 100%;
padding: 15px 0;
text-align: center;
color: white;
background: rgb(255 255 255 / 20%);
}
.shadow {
backdrop-filter: drop-shadow(4px 4px 5px black);
}
.invert {
backdrop-filter: invert(100%);
}
.opacity {
backdrop-filter: opacity(30%);
}
.saturate {
backdrop-filter: saturate(200%);
}
.sepia {
backdrop-filter: sepia(100%);
}
</style>
</head>
<body>
<h2>Backdrop Filter Effects</h2>
<div class="container">
<div class="box">
<div class="glass shadow">Drop Shadow</div>
</div>
<div class="box">
<div class="glass invert">Invert</div>
</div>
<div class="box">
<div class="glass opacity">Opacity</div>
</div>
<div class="box">
<div class="glass saturate">Saturate</div>
</div>
<div class="box">
<div class="glass sepia">Sepia</div>
</div>
</div>
</body>
</html>