brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: CSS backdrop-filter blurs whatever is behind an element

Css
~/tips/tip-css-backdrop-filter-blur

.header {

Applies effects such as blur to the area behind an element, for frosted glass headers and overlays.

A sticky header with a blurred, see-through background is a common look now. It takes one property, though a few things can make it silently do nothing.

.header {
  position: sticky;
  top: 0;
  background-color: rgb(255 255 255 / 30%);
  backdrop-filter: blur(10px);
}

backdrop-filter applies graphical effects to the area behind the element. The element or its background must be at least partly transparent, otherwise there is nothing to see through. That is why the background above has an alpha value.

It accepts filter functions such as blur(), brightness(), contrast(), grayscale(), saturate() and sepia(), and you can chain several, for example blur(8px) saturate(150%).

On support, MDN lists it as Baseline 2024, newly available, meaning it has worked across the latest browsers since September 2024. Older browsers may not support it, so make sure the page still reads well with only the semi-transparent background.

The caveat is the backdrop root. The effect only sees content up to the nearest ancestor that creates one. Things that do so include opacity below 1, a filter, a mask, a clip-path or mix-blend-mode other than normal on a parent. MDN names a parent with opacity: 0.9 as a typical reason the blur appears to do nothing. If it does not work, check the parents first.

Further reading: MDN: backdrop-filter

More Css tips CSS Overview in Chrome DevTools audits the colors and fonts of a page .notice:empty { .toast { article { counter-reset: h2; } .toolbar { All Css tips (66) All topics

Link