- !important
- 3D transform
- Animation
- Animation keyframes
- Background color
- Background image
- Blur() function
- Border color
- Border radius
- Border width
- Borders
- Box model
- Box shadow
- Class attribute
- Clear property
- Clip path
- Color
- Comment
- Container queries
- Cursor
- Display property
- Filter property
- First-child selector
- Flexbox
- Float property
- Focus
- Font family
- Font size
- Font style
- Font weight
- Gap
- Gradient
- Grid layout
- Height
- Hover
- ID selector
- Letter spacing
- Line height property
- Linking a style sheet
- Margin
- Media query
- Minmax() function
- N-th-child selector
- Object fit
- Opacity
- Outline
- Overflow property
- Padding
- Pixels
- Pointer events
- Position absolute
- Position fixed
- Position property
- Position sticky
- Pseudo-classes
- Pseudo-elements
- Quotes property
- Rotate
- Rounding an image
- Scale()
- Selectors
- Specificity
- Text align
- Text shadow
- Text wrap
- Transform property
- Transition property
- Translate() property
- Units
- Variable
- Viewport
- white-space
- Width
- Z-index
CSS
CSS Filter Property: Syntax, Usage, and Examples
The CSS filter property allows you to apply graphical effects to elements like images, backgrounds, or even text. With a single line of CSS, you can blur, brighten, invert, or otherwise manipulate the visual appearance of HTML elements. The filter property is particularly useful in modern web design for creating interactive UI effects, hover states, and visually appealing image displays.
You can apply filters to plain content, to a background image, or even to layered elements like icons and badges for quick styling snippets.
What Is the CSS Filter Property?
The CSS filter property applies visual effects to an element by altering the rendering of its pixels. Rather than modifying the element’s layout or content, the filter changes how the browser paints the element on the screen.
Many filters map directly to familiar image-processing ideas: a blur effect softens edges, color transforms tweak color values such as RGB, and shadows can be faked with filter-based lighting.
These effects are similar to those found in image editing tools like Photoshop and can be applied dynamically using transitions and animations.
When mixing visual styles, pair filters with background, background-color
, border, and shadow properties for cohesive results.
Basic Syntax
selector {
filter: function(value);
}
For example:
img {
filter: grayscale(100%);
}
This turns the image into black and white using a grayscale filter. If no filter is set, the default value is none, and the computed value reflects the list of specified filter values in order.
Common Filter Functions in CSS
The CSS filter property supports several built-in functions. You can apply one or multiple functions at once.
1. blur(px)
Blurs the element by the specified number of pixels.
img {
filter: blur(5px);
}
Under the hood, browsers approximate a gaussian blur, which is why the result looks smooth and natural.
2. brightness(%)
Adjusts the brightness. 100% is the original brightness.
img {
filter: brightness(150%);
}
3. contrast(%)
Changes the contrast. 100% is the original contrast.
img {
filter: contrast(200%);
}
4. grayscale(%)
Converts the image to shades of gray.
img {
filter: grayscale(100%);
}
5. invert(%)
Inverts the colors. 100% inverts all colors; 0% leaves them unchanged.
img {
filter: invert(100%);
}
6. opacity(%)
Adjusts transparency.
img {
filter: opacity(50%);
}
When deciding between filters and the opacity property, remember that CSS opacity affects the whole box (including children), while filter: opacity()
can be animated alongside other filters.
7. saturate(%)
Controls color saturation. 100% is normal; 0% is grayscale.
img {
filter: saturate(300%);
}
8. sepia(%)
Applies a sepia tone.
img {
filter: sepia(100%);
}
For design systems with vintage themes, a sepia filter pairs well with warm CSS color palettes.
9. drop-shadow(offsetX offsetY blurRadius color)
Adds a shadow that follows the shape of transparent images.
img {
filter: drop-shadow(4px 4px 10px rgba(0,0,0,0.5));
}
Offsets can use negative values (e.g., -4px -4px
) to cast the drop shadow effect up and left, unlike box-shadow
, which applies to the element’s box instead of the alpha shape.
Combining Multiple Filters
You can chain multiple functions together in a single CSS filter property declaration.
img {
filter: grayscale(100%) blur(3px) brightness(120%);
}
The order matters: filters are applied in sequence, so changing the order may lead to a different visual outcome.
If layered depth is needed, combine filters with stacking via z-index or decorative text-shadow while keeping headings readable with consistent text-align.
Filter Property in CSS with Transitions and Animations
The CSS filter property can be smoothly animated using the transition
property or keyframe animations.
Example: Image Hover Effect
img {
transition: filter 0.3s ease-in-out;
}
img:hover {
filter: brightness(80%) grayscale(50%);
}
This creates a subtle darkened grayscale effect when hovering over an image.
Example: Keyframes Animation
@keyframes blurAnimation {
0% {
filter: blur(0);
}
100% {
filter: blur(5px);
}
}
.blur-on-load {
animation: blurAnimation 1s ease-out forwards;
}
Animations allow you to introduce effects as the page loads or as elements come into view. For fancy typography, combine filters with text-rendering tweaks and decorative properties like text-decoration.
Fallbacks and Compatibility
The CSS filter property is supported in all major modern browsers:
- Chrome
- Firefox
- Safari
- Edge
- Opera
However, older versions of Internet Explorer (IE10 and earlier) do not support it. If backward compatibility is essential, avoid relying solely on filter effects for core functionality.
Always check browser support and consider graceful degradation. For text on images, cap widths with max-width, and stabilize layout with box-sizing so filtered content doesn’t overflow.
There is no need to use vendor prefixes for the filter property in modern environments.
Note: While filters alter painting, borders still follow border-width
and border-color
, and shadows from box-shadow
remain separate from the filter pipeline.
Performance Considerations
Although the CSS filter property is GPU-accelerated, applying too many filters—especially to large images or when animating—can affect performance.
Tips to maintain performance:
- Use filters sparingly, especially with animations.
- Avoid animating high-cost filters like
blur()
over large areas. - Limit the number of DOM elements affected simultaneously.
- Consider reducing image resolution if combining multiple effects.
For high-contrast UI, prefer drop-shadow()
or box-shadow
on small targets, and reserve heavy blur filter operations for short durations.
Accessibility and Usability Tips
The CSS filter property affects the visual presentation but not the underlying content. However, filters can reduce visibility or contrast, so be cautious:
- Avoid high
blur()
or lowopacity()
values for essential content. - Maintain sufficient color contrast when using
brightness()
andcontrast()
. - Use filters for decorative effects, not for conveying essential information.
- Test with screen readers to ensure content remains understandable when filters are used for interactivity.
When styling interactive elements, remember that ::before
and ::after
pseudo-elements can carry filters too, which helps separate decoration from content.
Real-World Use Cases for CSS Filter Property
1. Dimmed Background on Modal Activation
body.modal-open .page-content {
filter: brightness(50%);
}
Reduces background distraction when a modal or popup is active.
2. Image Effects for Galleries or Portfolios
.gallery img {
filter: grayscale(100%);
}
.gallery img:hover {
filter: none;
}
Creates a clean hover interaction to draw attention.
3. Emphasizing Buttons or UI Elements
button:focus {
filter: drop-shadow(0 0 5px #ff9900);
}
Adds a glowing effect on interaction or focus. If the design already uses box-shadow
on containers, keep consistency by matching the blur radius and color values.
4. Accessibility Enhancement for Visual Modes
You can apply invert()
and grayscale()
dynamically to create a "dark mode" or "reading mode."
body.dark-mode {
filter: invert(100%) hue-rotate(180deg);
}
Consider pairing with subtle text-shadow on headings to preserve legibility at lower contrast levels.
Creating Custom Visual Themes
Filters can be combined to create entirely new visual styles across entire pages.
Example: Vintage Look
body.vintage {
filter: sepia(80%) contrast(120%) brightness(90%);
}
This can be toggled via JavaScript or user preferences.
Example: Night Mode Overlay
.night-overlay {
position: fixed;
top: 0; left: 0;
width: 100%; height: 100%;
backdrop-filter: brightness(50%);
pointer-events: none;
}
Useful for user-focused night reading experiences.
Using Filters with SVG
Filters work beautifully with vector art. You can define an SVG <filter>
once and reuse it. The filter element accepts an input image from the source graphic and lets you combine primitives like feColorMatrix
or feGaussianBlur
.
<!-- 1) Define the SVG filter once (hidden) -->
<svg xmlns="http://www.w3.org/2000/svg" width="0" height="0" style="position:absolute">
<filter id="softBlur">
<feGaussianBlur stdDeviation="3" />
</filter>
</svg>
<!-- 2) Apply the filter via CSS to a regular HTML image -->
<img src="photo.jpg" alt="Example photo" class="blurred">
<style>
.blurred {
filter: url(#softBlur); /* uses the SVG filter defined above */
}
</style>
Background image example (filter applied to a div with a background):
<!-- Reuse the same <svg> with #softBlur from the first snippet -->
<div class="card"></div>
<style>
.card {
width: 240px;
height: 160px;
background: url('hero.jpg') center / cover no-repeat;
filter: url(#softBlur);
}
</style>
This is often called an SVG filter, and feGaussianBlur
is literally a vector-friendly gaussian blur that applies a soft, smooth blur filter to shapes or raster graphics.
You can also mix it with standard CSS filters for layered effects, like a subtle drop shadow effect combined with blur for glassmorphism or frosted-glass UIs.
Best Practices
- Use with Transitions Sparingly – Animating blur or brightness over large areas can be costly.
- Keep Accessibility in Mind – Avoid filters that interfere with readability.
- Combine with Other Effects – Blend filters with
transform
oropacity
for richer UI. - Avoid Filter Overload – Using too many filter functions simultaneously can create confusion.
- Test on Multiple Devices – GPU capabilities vary; test performance across platforms.
The CSS filter property is a flexible and creative tool for enhancing visual design on the web. With functions like blur, grayscale, brightness, and drop-shadow, it allows designers and developers to craft sophisticated visual effects without JavaScript or heavy graphic assets.
Sign up or download Mimo from the App Store or Google Play to enhance your programming skills and prepare for a career in tech.