Codectionary / Developer documentation / CSS

Filters

The filter property applies graphical effects like blur, brightness, contrast, and grayscale directly to an element, similar to Photoshop-style filters. backdrop-filter applies the same effects to the area behind an element instead, commonly used for frosted-glass UI effects. Multiple filter functions can be chained together.

Syntax

filter: blur() brightness() contrast() grayscale();

Examples

Common Filter Functions

Blurring, adjusting brightness, and desaturating an image.

.blurred { filter: blur(5px); }
.dimmed { filter: brightness(0.7); }
.grayscale { filter: grayscale(100%); }
.high-contrast { filter: contrast(1.4); }

/* Chaining multiple filters together */
.vintage { filter: sepia(0.5) contrast(1.1) brightness(0.9); }

backdrop-filter for Frosted Glass

Applying a blur to whatever is BEHIND a semi-transparent element - the popular glassmorphism effect.

.glass-panel {
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

Parameters and values

  • blur() (length): Gaussian blur effect
  • brightness() (percentage): Adjusts lightness, 100% is unchanged
  • grayscale() (percentage): Desaturates the element
  • backdrop-filter (same functions): Applies filters to content behind the element, not the element itself

Best practices

  • Use backdrop-filter specifically for frosted-glass effects over background content - filter alone only affects the element itself, not what is behind it
  • Chain multiple filter functions in one declaration for combined effects, rather than nesting elements to stack filters
  • Be mindful of performance - filters, especially blur, can be expensive to render on large areas or during animation
  • Test backdrop-filter with an actual background behind the element - it has no visible effect over a plain solid background

At a glance

Purpose
Presentation and layout
File extension
.css
Runs in
Web browsers
Usually used with
HTML and JavaScript

Specifications & further reading

Related CSS documentation