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.
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:
brightness(.85)
saturate(1.6)
brightness(.8)
saturate(2)
/* 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.
original
brightness(amount)
0 = pure black. 1 = normal. Above 1 = brighter. Common for hover darkening or lightening effects.
dark
normal
contrast(amount)
0 = flat grey. 1 = normal. Above 1 = punchy high contrast. Combines well with saturate for vivid looks.
grey
washed
normal
punchy
grayscale(amount)
0 = full colour. 1 = fully grey. Essential for disabled states, inactive tabs, and monochrome hover effects.
colour
grey
hue-rotate(angle)
Rotates all colours around the colour wheel. 0deg = original. 360deg = back to original. Accepts deg, turn, rad.
invert(amount)
0 = original. 1 = fully inverted (like a photo negative). Great for dark mode icon theming.
saturate(amount)
0 = greyscale. 1 = normal. Above 1 = hyper-vivid. Pairs beautifully with brightness for colour-pop hover effects.
grey
normal
vivid
sepia(amount)
0 = original. 1 = full warm brown vintage tone. Combine with hue-rotate to shift the warm tone to other colours.
opacity(amount)
Filter version of the
opacity property. Prefer the
standalone opacity property —
it's identical in modern browsers and more readable.
visible
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:
Shadow follows the bounding box,
ignores the star cutout
shape
Shadow traces the star silhouette
perfectly — no extra
box shadow
/* 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:
saturate(.8) brightness(.95)
brightness(1.1)
hue-rotate(-10deg)
hue-rotate(15deg)
opacity: .6
hue-rotate(180deg)
/* ── 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%):
background: rgba(255,255,255,.15)
/* ── 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 |
Try It Yourself
Hover the boxes to see filter transitions, explore drop-shadow vs box-shadow, and the live frosted glass scene:
Quick Check — Chapter 47
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.
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 changesThe 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.
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 →
white2.
sepia(1) shifts white
to a warm tone3.
saturate(5) adds vivid
colour to the warm tone4.
hue-rotate(200deg) shifts
the hue to the target colourOnline 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.
filter: grayscale(1) do?
filter: drop-shadow()
instead of box-shadow for
SVG icons?
filter: hue-rotate(180deg)
do to an element?
- 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-filterfor Safari.
Rate Us on Google
Join Our Learning Community
Connect with thousands of learners, get daily tips, ask questions and stay updated with new tutorials.