Menu

CSS Blur and Filter: blur(), grayscale, brightness

filter: blur(5px) blurs an element, and backdrop-filter: blur() blurs what is behind it. Learn every filter function (brightness, contrast, grayscale, sepia, saturate, hue-rotate, invert, drop-shadow) with live sliders, how to combine them, and the blur edge problem.

This page includes runnable editors - edit, run, and see output instantly.

Blur an element

filter: blur() takes a length, the blur radius. The larger it is, the blurrier the element:

filter works on any element, not only images: a blurred div blurs its text, border and children too. Notice the soft edges on the blurred images: the blur spreads the picture outward and mixes in the transparent area around it. The fix is below, under "The blurry edge problem".

Blur the background: backdrop-filter

To blur what is behind an element (a frosted glass panel over a photo or a page), use backdrop-filter. The element's own content stays sharp. It needs a see-through background to show the blur:

The stripes and circles are sharp around the panel and blurred behind it, while the panel's text is untouched. Keep the text readable: a lighter or darker tint in the background color helps on busy images.

Every filter function, live

Move any slider. The line under the image is the exact filter value, ready to copy:

Only functions you moved away from their neutral value are written out, which keeps the value short. brightness(1) or blur(0px) change nothing, so there is no reason to list them.

Filter functions

FunctionNeutral valueWhat it doesExample
blur(r)0Gaussian blur with radius rblur(4px)
brightness(n)1darker below 1, brighter abovebrightness(0.7)
contrast(n)1flatter below 1, punchier abovecontrast(1.3)
grayscale(n)01 (or 100%) is fully graygrayscale(100%)
sepia(n)0warm brown tonesepia(0.6)
saturate(n)10 is gray, above 1 more vividsaturate(1.5)
hue-rotate(a)0degshifts every hue around the color wheelhue-rotate(90deg)
invert(n)01 is a full color negativeinvert(1)
opacity(n)1like the opacity propertyopacity(0.5)
drop-shadow(x y blur color)a shadow that follows the shapedrop-shadow(2px 4px 6px rgb(0 0 0 / 0.3))

Numbers can also be percentages (grayscale(100%) equals grayscale(1)). Several functions go in one value, separated by spaces, and are applied in order: filter: grayscale(1) sepia(1) gives a brown tint, while sepia(1) grayscale(1) ends up plain gray.

drop-shadow follows the shape

box-shadow is always a rectangle (with rounded corners at most). drop-shadow() is drawn from the visible pixels, so a transparent icon gets a shadow with the icon's outline:

The first star casts a square shadow from its invisible bounding box. The second casts a star-shaped one. Unlike box-shadow, drop-shadow() has no spread value and no inset; the box-shadow page covers those.

The blurry edge problem

A blurred image fades out at its edges, because the blur pulls in the transparent pixels around it. To keep a hard edge (for a blurred hero background, for example), put the image in a container with overflow: hidden and scale the image up slightly so the soft edge is cut off:

.hero { overflow: hidden; }
.hero img { filter: blur(8px); transform: scale(1.1); }

Hover effects with filter

filter can be transitioned, so a gray-to-color logo wall or a dim-until-hovered card is two rules:

Hover (or tab to) a tile and its color fades in.

Good to know

  • Performance. Large blur radii on large areas cost the most, especially backdrop-filter on elements that move or scroll. Test on a phone.
  • Readability. Never blur text people need to read, and check contrast on text over a frosted panel.
  • Stacking. Any filter other than none creates a new stacking context and becomes the containing block for position: fixed descendants, like transform.

Common mistakes

  • filter: blur(5). The radius needs a unit: blur(5px).
  • Using filter: blur() for a frosted panel. It blurs the panel's own text. Use backdrop-filter with a transparent background.
  • A backdrop-filter that shows nothing. The background of the element must be at least partly transparent, and there must be something behind it.
  • Two filter declarations. The second replaces the first. Put all functions in one value.
  • Box-shaped shadows on transparent icons. Use filter: drop-shadow() instead of box-shadow.

Frequently Asked Questions

How do I blur an element in CSS?

Use filter: blur(5px);. The length is the blur radius: 0 is sharp and larger values are blurrier. It blurs the element and everything inside it, including its text and images.

How do I blur the background behind an element?

Use backdrop-filter: blur(10px); on the element, with a partly transparent background such as rgb(255 255 255 / 0.5). The element's own content stays sharp and whatever is behind it is blurred, the frosted glass effect.

What is the difference between drop-shadow() and box-shadow?

box-shadow always follows the element's rectangular box. filter: drop-shadow() follows the visible shape, including transparent areas of a PNG or SVG, so an icon's shadow has the icon's outline.

How do I make an image black and white in CSS?

Use filter: grayscale(100%); (or grayscale(1)). Add a transition and filter: grayscale(0) on hover to bring the color back.

Can I use several filters at once?

Yes, list them separated by spaces: filter: grayscale(1) brightness(1.2) blur(1px);. They are applied in order, so the order can change the result. A second filter declaration replaces the first.

Coddy programming languages illustration

Learn to code with Coddy

GET STARTED