CSS Blur: Blur Text, Images and Backgrounds

By Marko Denic
Contents
  1. filter: blur()
  2. Blur an image or element
  3. Fix the soft, faded edges
  4. Blurred background image, sharp content
  5. backdrop-filter: the frosted glass effect
  6. Blur what's behind an element
  7. Blurred sticky header
  8. Blurred text
  9. With text-shadow
  10. Spoiler: blurred until hover or focus
  11. Performance
  12. FAQ

CSS has two blur tools, and they blur different things:

  • filter: blur(8px) blurs the element itself: its content, text, images and background.
  • backdrop-filter: blur(8px) blurs what’s behind the element, which is how frosted glass effects work.

The number is the blur radius: the higher it is, the blurrier the result.

Demo:

backdrop-filter
filter

Blurred text

Hover to reveal the spoiler

filter: blur()

Blur an image or element

filter: blur() takes a length (px, rem, not percentages) and blurs everything the element renders, including its children.

css
img.preview {
  filter: blur(8px);
}

/* Combine with other filters */
img.dimmed {
  filter: blur(4px) brightness(0.7);
}

Fix the soft, faded edges

A blurred image also blurs its edges into the background, leaving a faded halo. Clip it inside a container with overflow: hidden and scale the image up a little so the blur stays inside.

css
.blur-frame {
  overflow: hidden;
  border-radius: 12px;
}

.blur-frame img {
  display: block;
  filter: blur(10px);
  transform: scale(1.1); /* hides the faded edges */
}

Blurred background image, sharp content

Blurring a parent blurs its text too. Put the image on a ::before pseudo-element instead, blur only that, and keep the content on top.

css
.hero {
  position: relative;
  overflow: hidden;
  isolation: isolate;
}

.hero::before {
  content: "";
  position: absolute;
  inset: -20px;               /* bigger than the box: no faded edges */
  z-index: -1;
  background: url("hero.jpg") center / cover;
  filter: blur(12px) brightness(0.8);
}

backdrop-filter: the frosted glass effect

Blur what's behind an element

backdrop-filter only shows through where the element’s own background is transparent, so give it a semi-transparent background color. It’s supported in all current browsers; add -webkit-backdrop-filter if you need to support Safari versions older than 18. Generate the whole effect visually with the glassmorphism CSS generator.

css
.glass {
  background: rgb(255 255 255 / 0.2);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border: 1px solid rgb(255 255 255 / 0.3);
  border-radius: 16px;
}

Blurred sticky header

A popular use: a header that blurs the page scrolling under it.

css
.site-header {
  position: sticky;
  top: 0;
  background: rgb(255 255 255 / 0.7);
  backdrop-filter: blur(10px);
}

Blurred text

With text-shadow

Make the text color transparent and draw it with a blurred text-shadow. The text stays selectable and in the HTML. A larger blur radius means blurrier text.

css
.blurred-text {
  color: transparent;
  text-shadow: 0 0 6px #0f172a;
}

Spoiler: blurred until hover or focus

Hide spoilers, answers or sensitive info behind a blur, and reveal it on hover. Add :focus with tabindex="0" so keyboard and touch users can reveal it too.

css
.spoiler {
  filter: blur(5px);
  transition: filter 0.3s;
  cursor: pointer;
}

.spoiler:hover,
.spoiler:focus {
  filter: none;
}

Performance

Blur is one of the more expensive effects to draw, especially backdrop-filter, which has to redraw whenever anything behind it moves. Keep blurred areas small, avoid animating the blur radius on large elements, and test scrolling on a mid-range phone. For a static blurred background, a pre-blurred image file is cheaper than a live filter. More on keeping pages fast in web performance.

FAQ

How do I blur a background image in CSS?

Put the image on a pseudo-element or separate layer behind the content and apply filter: blur() to that layer only, so the text stays sharp.

What’s the difference between filter: blur and backdrop-filter: blur?

filter blurs the element and its contents. backdrop-filter blurs whatever is visible behind the element, through its transparent background.

Why isn’t backdrop-filter working?

The element’s background is probably opaque. Use a semi-transparent color like rgb(255 255 255 / 0.2). Also check that there’s something behind it to blur.

Can I blur only part of an image?

Yes: place an element over that part with backdrop-filter: blur() and a transparent background.