w3tweaks.com · CSS Tutorial

CSS filter & backdrop-filter

Live playground, glassmorphism, filter-order gotcha, and real UI patterns.

Tab 1

filter — Live Playground

Drag any slider to apply the filter. Stack multiple filters and see both the visual result and the generated CSS instantly.

Quick presets
Preview
filter: none;
blur0px
brightness100%
contrast100%
grayscale0%
hue-rotate0deg
invert0%
saturate100%
sepia0%
⚠️ Filter Order Matters

Filters are applied left to right, each one operating on the output of the previous. The same filters in different order produce different results:

grayscale(100%) hue-rotate(90deg)

Result: gray — grayscale removes all color first, so hue-rotate has nothing to rotate

hue-rotate(90deg) grayscale(100%)

Result: also gray — but different gray values. The hue-rotate ran first and changed luminance before grayscale converted it.
Tab 2

backdrop-filter — Glass Effects

backdrop-filter applies to the content behind the element — the element must be semi-transparent to reveal it. Click presets or drag the slider.

Frosted Glass Card
Glassmorphism Card
blur(14px) saturate(160%)
Frosted Glass Nav
Page content below the nav
W3Tweaks CSS JS HTML
Blurred Modal Overlay
Modal Dialog
Content behind is blurred
🎨 hue-rotate() — Instant Color Theming
Card
Nav
Button
Badge
Alert
0deg
/* Apply to the root — shifts ALL colors in entire UI */
:root { filter: hue-rotate(0deg); }

Applying hue-rotate() to :root or a page wrapper rotates every color on the page simultaneously — an instant theme switcher with one CSS value.

⚠️ iOS Safari + position:fixed + backdrop-filter: Applying backdrop-filter to a position:fixed element on iOS Safari can cause severe scroll performance issues — the blurred content repaints on every scroll frame. Workaround: use position:sticky instead, or limit backdrop-filter to elements that don't move during scroll.
Tab 3

Real-World Patterns

Hover the demos where indicated. All effects are CSS-only.

✨ Hover Brightness & Contrast
🌟
🎨
🔥
👁️
.card:hover { filter: brightness(1.3); }
.img { filter: grayscale(100%); }
.img:hover { filter: grayscale(0); }

Hover each card. Top: brightness, bottom-left: grayscale-to-color on hover, bottom-right: blur removes on hover.

💡 drop-shadow() vs box-shadow
box-shadow (rect)
drop-shadow (shape)
/* Follows the box model — rectangular */
box-shadow: 4px 4px 12px rgba(0,0,0,.5);
/* Follows the alpha channel — shape-aware */
filter: drop-shadow(4px 4px 6px rgba(0,0,0,.5));

drop-shadow() follows the element's transparent pixels — perfect for icons, PNGs, and SVGs. box-shadow follows the rectangular bounding box.

🚫 Out-of-Stock Grayout
👟
In stock
👟
Size 9
👕
In stock
🎒
Bag
.out-of-stock {
  filter: grayscale(100%) opacity(0.6);
  cursor: not-allowed;
}

No extra CSS classes or image variants needed — filter visually communicates unavailability on any element.

💜 Neon Glow with drop-shadow()
Hover for glow ✦
/* Stack multiple drop-shadows for neon */
.neon:hover {
  filter:
    drop-shadow(0 0 6px currentColor)
    drop-shadow(0 0 20px currentColor);
}

Stacking multiple drop-shadow() with increasing radius creates a realistic neon glow. currentColor ties the glow to the element's text color.

🖼️ Lightweight Blurred Background
Text over blurred bg
.bg {
  filter: blur(8px) brightness(0.7);
  transform: scale(1.1); ← hides blur edge
}

Load a tiny thumbnail, apply heavy blur() — the browser can't tell the difference. A 4KB image becomes a 2MB-quality hero background.

🧊 Frosted Glass Sticky Nav
.nav {
  background: rgba(11,15,26, 0.5);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

The -webkit- prefix is still required for Safari support. Always include both declarations.

filter creates a stacking context: Any value of filter other than none creates a new stacking context — exactly like opacity. This means children of a filtered element cannot z-index above elements outside it. If you're fighting a z-index battle and nothing works, check if an ancestor has a filter applied. See CSS z-index & stacking contexts for the full explanation.
Read the tutorial