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.


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.

These effects are similar to those found in image editing tools like Photoshop and can be applied dynamically using transitions and animations.

Basic Syntax

selector {
  filter: function(value);
}

For example:

img {
  filter: grayscale(100%);
}

This turns the image into black and white using a grayscale filter.


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);
}

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%);
}

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%);
}

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));
}

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.


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.


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.

There is no need to use vendor prefixes for the filter property in modern environments.


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.

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 low opacity() values for essential content.
  • Maintain sufficient color contrast when using brightness() and contrast().
  • 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.

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.

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);
}

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.


Best Practices

  1. Use with Transitions Sparingly – Animating blur or brightness over large areas can be costly.
  2. Keep Accessibility in Mind – Avoid filters that interfere with readability.
  3. Combine with Other Effects – Blend filters with transform or opacity for richer UI.
  4. Avoid Filter Overload – Using too many filter functions simultaneously can create confusion.
  5. 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.

Learn CSS for Free
Start learning now
button icon
To advance beyond this tutorial and learn CSS by doing, try the interactive experience of Mimo. Whether you're starting from scratch or brushing up your coding skills, Mimo helps you take your coding journey above and beyond.

Sign up or download Mimo from the App Store or Google Play to enhance your programming skills and prepare for a career in tech.

You can code, too.

© 2025 Mimo GmbH

Reach your coding goals faster