CSS Filters
Apply visual effects like blur, brightness, contrast, and drop shadows to elements. Create stunning photo filters, glass effects, and artistic transformations with CSS.
What does the CSS filter property do?
filter applies graphical effects like blur(), brightness(), contrast(), grayscale(), saturate(), sepia(), hue-rotate() and drop-shadow() to an element and everything inside it. backdrop-filter applies the same effects to whatever is behind the element, which is how frosted-glass panels are made.
img.muted:hover { filter: grayscale(0); }
img.muted { filter: grayscale(1) contrast(1.1); transition: filter .3s; }
.glass {
background: rgb(255 255 255 / .6);
backdrop-filter: blur(12px);
}Interactive CSS Filters Demo
Code Editor
<div class="grid">
<figure><img src="https://picsum.photos/id/1025/200/140" alt="Dog"><figcaption>none</figcaption></figure>
<figure><img class="gray" src="https://picsum.photos/id/1025/200/140" alt="Dog"><figcaption>grayscale(1)</figcaption></figure>
<figure><img class="blur" src="https://picsum.photos/id/1025/200/140" alt="Dog"><figcaption>blur(3px)</figcaption></figure>
<figure><img class="combo" src="https://picsum.photos/id/1025/200/140" alt="Dog"><figcaption>sepia + contrast</figcaption></figure>
</div>Preview
Filter Fundamentals
CSS filters apply visual effects to elements, including blur, color adjustments, shadows, and more. They're hardware-accelerated and can be combined for complex effects.
Filter Syntax
filter: function(value) function(value);
filter: blur(5px) brightness(1.2) contrast(1.5);
filter: drop-shadow(4px 4px 8px rgba(0,0,0,0.3));Combine functions: Space-separated list
Order matters: Functions apply sequentially
Hardware accelerated: GPU optimized
Real-time effects: Dynamic and interactive
Core Filter Functions
CSS provides a comprehensive set of filter functions for different types of visual effects, from basic adjustments to artistic transformations.
Basic Adjustments
brightness(1.2)
contrast(1.5)
opacity(0.8)Control light, contrast, and transparency
Color Effects
hue-rotate(90deg)
saturate(2)
invert(100%)Manipulate colors and hues
Artistic Effects
blur(5px)
sepia(100%)
grayscale(100%)Create artistic and vintage effects
Drop Shadows & Advanced Effects
The drop-shadow function creates shadows that follow the shape of elements, unlike box-shadow which creates rectangular shadows.
Drop Shadow Syntax
drop-shadow(offset-x offset-y blur-radius color)
drop-shadow(4px 4px 8px rgba(0,0,0,0.3))
drop-shadow(0 0 10px #667eea) /* Glow effect */Key difference: drop-shadow follows element shape, while box-shadow creates rectangular shadows
Multiple Shadows
filter:
drop-shadow(2px 2px 4px red)
drop-shadow(-2px -2px 4px blue);Combine multiple drop-shadow functions for complex effects
Backdrop Filter
backdrop-filter: blur(10px);
backdrop-filter: saturate(180%);
backdrop-filter: brightness(1.1);Apply filters to elements behind the current element
Filter Combinations & Performance
Filter Combinations
/* Vintage photo effect */
filter:
sepia(60%)
contrast(1.2)
brightness(0.9)
saturate(1.4);Combine multiple functions for photo-like effects
Performance Tips
- • Filters are GPU-accelerated for better performance
- • Use will-change: filter for animated filters
- • Minimize filter complexity on mobile devices
- • Test performance on lower-end hardware
- • Consider fallbacks for older browsers
Most filter functions have excellent browser support. However, backdrop-filter has limited support in older browsers. Always provide fallbacks and test across different browsers and devices.
CSS Filters — step by step
Basic Filter Functions
Apply image effects: blur(4px) softens, brightness(1.2) lightens, contrast(1.5) sharpens, grayscale(1) converts to black-and-white.
🎯 Quick Check
Which filter property blurs the content BEHIND an element?
CSS Filters: summary
Key points
- Filters can be chained and are applied in order.
- A filter creates a stacking context and a containing block for
fixeddescendants. - Large blur radii are expensive on low-end devices.
Frequently asked questions
›How do I make a frosted glass effect?
Give the element a semi-transparent background and backdrop-filter: blur(10px). It needs something visible behind it to blur.
›How do I make an image black and white with CSS?
Use filter: grayscale(100%). Transition back to grayscale(0) on hover for a colour reveal.