Tutorials CSS CSS Filters
Ch 47 / 60
Chapter 47 Beginner 8 min read CSS

CSS Filters

The CSS filter property applies Photoshop-like visual effects directly in the browser — blur, brightness, contrast, grayscale, hue rotation, inversion, saturation, sepia tone, and shape-aware drop shadows. All 10 functions can be combined and animated with transitions. The companion backdrop-filter applies these same effects to the content behind an element, enabling the popular frosted glass UI pattern used in modern navbars, modals, and cards.

What you'll learn
All 10 CSS filter functions with live demos
blur, brightness, contrast, grayscale
hue-rotate, invert, saturate, sepia, opacity
drop-shadow() vs box-shadow
Combined filter recipes
backdrop-filter — frosted glass

filter Syntax & Hover Demos

The filter property accepts one or more space-separated filter functions applied left to right. Every filter can be animated with transition: filter. Hover each box below to see the filter applied live:

Hover
grayscale(1)
brightness(.85)
Hover
brightness(1.5)
saturate(1.6)
Hover
brightness(.45)
Hover
blur(4px)
brightness(.8)
Hover
sepia(1)
Hover
invert(1)
Hover
hue-rotate(180deg)
saturate(2)
Hover
saturate(5)
Hover
contrast(2.5)
CSS — filter syntax
/* Single filter */
.el { filter: grayscale(1); }
.el { filter: blur(4px); }

/* Multiple filters — space-separated, applied left → right */
.el { filter: blur(2px) brightness(1.2) saturate(1.5); }

/* Animated hover — transition: filter */
.photo       { filter: saturate(1);     transition: filter .3s ease; }
.photo:hover { filter: saturate(1.5) brightness(1.05) contrast(1.1); }

/* Disabled state */
.disabled    { filter: grayscale(1) brightness(.9); opacity: .6; }

/* none — remove all filters */
.el { filter: none; }

All 10 Filter Functions

Each function is shown on an identical gradient tile so you can clearly see its effect. The tile is background: linear-gradient(135deg, #264de4, #a855f7, #22c55e).

blur(radius)

Gaussian blur. 0 = sharp. Higher = more blurred. Use for skeletons, depth of field, modal backdrops.

CSS
blur(0)
original
CSS
blur(2px)
CSS
blur(5px)
CSS
blur(10px)

brightness(amount)

0 = pure black. 1 = normal. Above 1 = brighter. Common for hover darkening or lightening effects.

brightness(.3)
dark
brightness(.7)
brightness(1)
normal
brightness(1.5)
brightness(2)

contrast(amount)

0 = flat grey. 1 = normal. Above 1 = punchy high contrast. Combines well with saturate for vivid looks.

contrast(0)
grey
contrast(.5)
washed
contrast(1)
normal
contrast(1.5)
contrast(2)
punchy

grayscale(amount)

0 = full colour. 1 = fully grey. Essential for disabled states, inactive tabs, and monochrome hover effects.

grayscale(0)
colour
grayscale(.5)
grayscale(1)
grey

hue-rotate(angle)

Rotates all colours around the colour wheel. 0deg = original. 360deg = back to original. Accepts deg, turn, rad.

hue-rotate(0)
hue-rotate(90deg)
hue-rotate(180deg)
hue-rotate(270deg)

invert(amount)

0 = original. 1 = fully inverted (like a photo negative). Great for dark mode icon theming.

invert(0)
invert(.5)
invert(1)

saturate(amount)

0 = greyscale. 1 = normal. Above 1 = hyper-vivid. Pairs beautifully with brightness for colour-pop hover effects.

saturate(0)
grey
saturate(1)
normal
saturate(2)
saturate(4)
vivid

sepia(amount)

0 = original. 1 = full warm brown vintage tone. Combine with hue-rotate to shift the warm tone to other colours.

sepia(0)
sepia(.5)
sepia(1)

opacity(amount)

Filter version of the opacity property. Prefer the standalone opacity property — it's identical in modern browsers and more readable.

opacity(1)
visible
opacity(.5)
opacity(.2)
faint

filter: drop-shadow() vs box-shadow

box-shadow always follows the element's rectangular bounding box. filter: drop-shadow() traces the actual painted pixel silhouette — including transparent cutouts, PNG images, SVG shapes and clip-path polygons:

✗ box-shadow — rectangular

Shadow follows the bounding box,
ignores the star cutout shape

✓ drop-shadow() — pixel-perfect

Shadow traces the star silhouette
perfectly — no extra box shadow

CSS — drop-shadow filter
/* drop-shadow(offset-x offset-y blur-radius color)
   No spread-radius — unlike box-shadow */

.png-icon  { filter: drop-shadow(2px 4px 8px rgba(0,0,0,.4)); }
.svg-logo  { filter: drop-shadow(0 3px 6px rgba(0,0,0,.3)); }
.star-clip { filter: drop-shadow(4px 4px 0 rgba(0,0,0,.6)); }

/* Hover — lift with shape-correct shadow */
.icon      {
  filter:    drop-shadow(0 2px 4px rgba(0,0,0,.2));
  transition:filter .3s ease, transform .3s ease;
}
.icon:hover{
  filter:    drop-shadow(0 8px 16px rgba(0,0,0,.35));
  transform: translateY(-4px);
}

/* Coloured glow on icon */
.icon-blue{ filter: drop-shadow(0 4px 10px rgba(38,77,228,.6)); }

/* When to use which:
   box-shadow   → cards, buttons, rectangular elements
   drop-shadow  → PNGs, SVGs, clip-path shapes, emojis */

Combined Filter Recipes

Space-separate multiple filters — they chain left to right. These are battle-tested recipes for real UI and photo-processing effects:

Vintage
sepia(.7) contrast(1.1)
saturate(.8) brightness(.95)
Mono B&W
saturate(0) contrast(1.3)
brightness(1.1)
Cinematic
contrast(1.1) saturate(.8)
hue-rotate(-10deg)
Warm Vivid
saturate(1.5) brightness(1.1)
hue-rotate(15deg)
Disabled
grayscale(1) brightness(.9)
opacity: .6
Dark Mode Icon
invert(1)
hue-rotate(180deg)
CSS — all filter functions + recipes
/* ── All 10 filter functions ── */
.el { filter: blur(4px); }               /* 0 = sharp */
.el { filter: brightness(1.5); }        /* 0=black 1=normal 2=double */
.el { filter: contrast(2); }            /* 0=grey 1=normal */
.el { filter: grayscale(1); }           /* 0=colour 1=grey */
.el { filter: hue-rotate(180deg); }    /* rotates colour wheel */
.el { filter: invert(1); }              /* 0=normal 1=inverted */
.el { filter: opacity(.5); }            /* prefer standalone opacity */
.el { filter: saturate(2); }            /* 0=grey 1=normal 4=vivid */
.el { filter: sepia(1); }               /* 0=normal 1=warm brown */
.el { filter: drop-shadow(2px 4px 8px rgba(0,0,0,.4)); }

/* ── Recipes ── */

/* Vintage photo */
.vintage    { filter: sepia(.7) contrast(1.1) saturate(.8) brightness(.95); }

/* Mono / black and white */
.mono       { filter: saturate(0) contrast(1.3) brightness(1.1); }

/* Cinematic cool grade */
.cinematic  { filter: contrast(1.1) saturate(.8) brightness(.95) hue-rotate(-10deg); }

/* Warm vivid punch */
.warm       { filter: saturate(1.5) brightness(1.1) hue-rotate(15deg); }

/* Disabled element */
.disabled   { filter: grayscale(1) brightness(.9); opacity: .6; }

/* Dark-mode icon (black icon → readable on dark) */
@media (prefers-color-scheme: dark) {
  .icon-light { filter: invert(1) hue-rotate(180deg); }
}

/* Animated rainbow hue rotation */
@keyframes rainbow { to { filter: hue-rotate(360deg); } }
.rainbow    { animation: rainbow 4s linear infinite; }

/* Hover colour pop */
.card-img      { filter: saturate(.9); transition: filter .3s ease; }
.card-img:hover{ filter: saturate(1.4) brightness(1.05) contrast(1.1); }

backdrop-filter — Frosted Glass

backdrop-filter applies effects to what's behind the element — not the element itself. The element must be semi-transparent for the effect to show through. The live demo below uses actual CSS backdrop-filter: blur(14px) saturate(160%):

Glass Panel
backdrop-filter: blur(14px) saturate(160%)
background: rgba(255,255,255,.15)
CSS — backdrop-filter patterns
/* ── Frosted glass card ── */
.glass {
  background:             rgba(255,255,255,.15);  /* must be transparent */
  backdrop-filter:        blur(12px) saturate(180%);
  -webkit-backdrop-filter:blur(12px) saturate(180%); /* Safari */
  border:                 1px solid rgba(255,255,255,.2);
  border-radius:          12px;
}

/* ── Frosted navbar ── */
.nav-frosted {
  position:               sticky; top: 0;
  background:             rgba(255,255,255,.65);
  backdrop-filter:        blur(20px) saturate(120%);
  -webkit-backdrop-filter:blur(20px) saturate(120%);
  border-bottom:          1px solid rgba(255,255,255,.3);
}

/* ── Dark glass (dark navbar) ── */
.nav-dark {
  background:      rgba(15,23,42,.6);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

/* ── Blurred modal backdrop ── */
.modal-overlay {
  position:        fixed; inset: 0;
  background:      rgba(0,0,0,.4);
  backdrop-filter: blur(4px);
}

/* ── Fallback for browsers without backdrop-filter ── */
@supports not (backdrop-filter: blur(1px)) {
  .glass { background: rgba(255,255,255,.88); }
}

/* Browser support (2025): Chrome 76+, Firefox 103+, Safari 9+ (prefix) */

Filter Functions Reference

Function Range Default Best used for
blur(radius) 0px → any 0 Loading skeletons, depth of field, modal backdrops
brightness(n) 0 → ∞ 1 Hover darkening/brightening, disabled elements
contrast(n) 0 → ∞ 1 Image enhancement, punchy hover effects
grayscale(n) 0 → 1 0 Disabled/inactive state, desat hover
hue-rotate(deg) 0deg → 360deg 0deg Colour themes, rainbow animation
invert(n) 0 → 1 0 Dark mode icons, negative effect
opacity(n) 0 → 1 1 Prefer standalone opacity property
saturate(n) 0 → ∞ 1 Colour pop hover, muted/vivid presets
sepia(n) 0 → 1 0 Vintage look, warm mono effect
drop-shadow() x y blur color none PNG icons, SVG shapes, clip-path elements
Free Resource
CSS3 Cheat Sheet — All Properties & Filter Patterns
Complete reference covering all CSS filter functions, backdrop-filter and frosted glass patterns.
Download PDF

Try It Yourself

Hover the boxes to see filter transitions, explore drop-shadow vs box-shadow, and the live frosted glass scene:

Live Editor
✎ Editor
👁 Preview
Featured Course — Enroll Now
Modern Web Development With AI
Master HTML, CSS, JavaScript, React and Node.js with real projects and placement support.
120+
Chapters
40 hrs
Content
10 Real
Projects
4.9 ⭐
Rating
HTML5CSS3JavaScriptReact.jsNode.jsTailwind CSSAI Tools

Quick Check — Chapter 47

Questions & Answers
filter applies effects to the element itself and all its children. If you apply filter: grayscale(1) to a div, the div and everything inside it turns grey.

backdrop-filter applies effects to the area behind the element — what you see through it. The element itself is unaffected. For the effect to be visible, the element must be semi-transparent (using background: rgba(…)).

This distinction enables the frosted glass effect: the glass panel itself has a near-transparent background, and backdrop-filter blurs whatever is behind it. A fully opaque element would hide the backdrop entirely, making backdrop-filter pointless.
box-shadow uses the element's CSS box model — always a rectangle (possibly with border-radius). It cannot see the actual visual content of the element.

filter: drop-shadow() reads the element's alpha channel — its actual painted, visible pixels. Transparent areas are excluded from the shadow calculation. This means:
— A star shape via clip-path: drop-shadow follows the star; box-shadow shadows the bounding rectangle
— A PNG logo with transparent background: drop-shadow follows the logo silhouette; box-shadow shadows the full rectangular image element
— An SVG icon: drop-shadow traces every curve; box-shadow boxes it

Key difference: drop-shadow also does not support spread-radius or inset — those are box-shadow-only features.
Use transition: filter duration easing on the base state, then change the filter value in a hover, focus, or class-change state.

.photo { filter: saturate(1); transition: filter .3s ease; }
.photo:hover { filter: saturate(1.5) brightness(1.05); }

Best practice: define the same filter functions in both states for smooth interpolation. If the base has no filter and hover adds one, the browser must infer the "zero" value — this usually works but can look abrupt.

Filters can also be animated with @keyframes for continuous effects, like an infinite hue rotation:
@keyframes rainbow { to { filter: hue-rotate(360deg) } }
.el { animation: rainbow 4s linear infinite; }
.disabled { filter: grayscale(1) brightness(.9); opacity: .6; pointer-events: none; }

Each part plays a role:
— grayscale(1): removes all colour — the universal visual cue for "unavailable"
— brightness(.9): slightly darkens — adds to the muted, inactive feel
— opacity: .6: further reduces visual presence — reinforces that it's not primary content
— pointer-events: none: disables all mouse interaction including cursor changes

The filter approach is superior to manually greying out colours because it works on any element regardless of its internal styles — a button, a card, an icon, a form — all become uniformly grey with one rule.
The simplest approach: filter: invert(1) — turns black → white and white → black.

@media (prefers-color-scheme: dark) { .icon { filter: invert(1); } }

For a more refined result that converts a black icon to a specific brand colour, chain multiple filters:
filter: invert(1) sepia(1) saturate(5) hue-rotate(200deg);

How this works:
1. invert(1) turns black → white
2. sepia(1) shifts white to a warm tone
3. saturate(5) adds vivid colour to the warm tone
4. hue-rotate(200deg) shifts the hue to the target colour

Online tools like "CSS filter generator to colour" can calculate the exact filter chain needed to reach any specific hex value from a black starting icon.
Multiple Choice Questions
Question 1 of 5
What does filter: grayscale(1) do?
Question 2 of 5
Which property creates a frosted glass effect on a semi-transparent element?
Question 3 of 5
Why should you use filter: drop-shadow() instead of box-shadow for SVG icons?
Question 4 of 5
What does filter: hue-rotate(180deg) do to an element?
Question 5 of 5
Which CSS correctly smoothly desaturates a photo to grey on hover?
Chapter Summary
  • filter: applies effects to the element and its children. Space-separate multiple functions; they chain left to right.
  • blur(radius): Gaussian blur. 0 = sharp. Higher = more blurred. For loading skeletons, depth of field.
  • brightness(n): 0 = black, 1 = normal, 2 = double. Hover darkening/brightening.
  • contrast(n): 0 = grey, 1 = normal, 2 = high contrast. Image enhancement.
  • grayscale(0–1): converts to grey. Essential for disabled/inactive states.
  • hue-rotate(angle): rotates all hues around the colour wheel. 360deg = original.
  • invert(0–1): inverts colours. For dark mode icon theming: invert(1).
  • saturate(n): 0 = grey, 1 = normal, 4 = vivid. Colour pop on hover.
  • sepia(0–1): warm brown vintage effect.
  • drop-shadow(x y blur color): shadow follows actual pixel shape — use on PNGs, SVGs, clip-path elements. No spread or inset.
  • Animating filters: transition: filter .3s ease. Define same functions in both states for smooth interpolation.
  • backdrop-filter: applies to content behind a semi-transparent element. Frosted glass: background: rgba(255,255,255,.15); backdrop-filter: blur(12px) saturate(180%). Always include -webkit-backdrop-filter for Safari.
~8 min read
Beginner level
Chapter 47 of 60

Rate Us on Google

4.8 / 5
Enjoying this tutorial?
Your 5-star review helps other learners discover our free tutorials and encourages us to keep creating quality content.
80+ reviews
Write a Google Review
Join WhatsApp Channel