CSS Filter Generator

Build a CSS filter from sliders for blur, brightness, contrast, saturation, greyscale, sepia, hue rotation, invert, opacity and drop shadow, with a live preview.

Loading tool…

The CSS is generated by JavaScript in your browser and never leaves the page. There is nothing to upload and nothing is stored.

What the CSS Filter Generator does

The CSS filter generator on this page will build a CSS filter from sliders for blur, brightness, contrast, saturation, greyscale, sepia, hue rotation, invert, opacity and drop shadow, with a live preview. Everything runs inside this page, so the work happens on your own device rather than on a server. It is most often used for dimming or desaturating an image for use behind text. For a second version of this CSS filter generator, see FreeToolsWorld.org.

How to use it

  1. Move the sliders for the effects you want.
  2. Watch the preview — the colour blocks make hue rotation, saturation and sepia easy to judge.
  3. Turn on the drop shadow if you need one, and set its offset, blur and colour.
  4. Copy the filter declaration. Only the functions you have moved are included.

How it works

The filter property takes a list of functions applied in order, left to right, and the order genuinely changes the result. grayscale(100%) sepia(100%) gives a sepia tone, because the greyscale step runs first and the sepia then tints the grey. sepia(100%) grayscale(100%) gives plain grey, because the tint is applied and then stripped out again. The same is true of blur before and after a drop shadow: one blurs the shape and then shadows the blurred version, the other shadows the sharp shape and blurs both together.

Each function has a value that means "do nothing" — 0 for blur, greyscale, sepia and invert, 100% for brightness, contrast, saturation and opacity, 0deg for hue rotation. This generator leaves the untouched ones out of the output entirely, because a filter string that lists all nine at their identity values is noise in a stylesheet and slower to read. Nine functions where one is doing the work tells the next reader nothing about which one matters.

drop-shadow is the one worth understanding properly, because it is not box-shadow. box-shadow draws the shadow of the element’s box: a rectangle, or a rounded rectangle if there is a border radius. drop-shadow follows the alpha channel, so a transparent PNG, an SVG icon or text casts a shadow of the actual shape. For an icon that is the difference between a usable shadow and an obviously wrong rectangle behind it. The cost is that it is more expensive to paint, and unlike box-shadow it has no spread parameter.

Two practical limits are worth knowing before you ship a filter. A blur applies to the element’s edges as well as its content, so a blurred image fades out at its boundary — wrap it in a container with overflow: hidden if you need the edges to stay crisp. And any filter other than none creates a containing block for fixed and absolutely positioned descendants, the same way transform does, which can move a child that was positioned against the viewport. If something inside a filtered element jumps, that is why.

Filters are composited on the GPU in every current browser, so animating one is cheap compared with animating a layout property — but animating blur in particular forces a re-rasterisation on each frame and is the one filter that can still drop frames on a phone. Animating opacity or brightness is safe; a blur transition on a large element is worth testing on a real device.

When to use it

  • Dimming or desaturating an image for use behind text.
  • Building a hover effect that brightens or saturates a thumbnail.
  • Giving an SVG icon or a transparent PNG a shadow of its actual shape.
  • Converting a colour illustration to greyscale or sepia without editing the file.
  • Working out the exact filter string to put in a stylesheet or a Tailwind arbitrary value.

Common mistakes to avoid

  • Assuming the order of functions does not matter. grayscale then sepia is not sepia then grayscale.
  • Using drop-shadow where box-shadow is meant, or the reverse. One follows the shape, the other the box.
  • Listing every filter function at its identity value, which says nothing about what the rule does.
  • Forgetting that a blur softens the element’s own edges, not just its content.
  • Not realising a filter creates a containing block, which can reposition absolutely positioned children.
  • Animating a large blur, which is the one filter expensive enough to drop frames on a phone.

Frequently asked questions

Does the order of CSS filter functions matter?

Yes, and often dramatically. Filters are applied in the order written, so grayscale(100%) sepia(100%) produces a sepia tone while sepia(100%) grayscale(100%) produces plain grey. Reordering is a legitimate way to get a different look from the same values.

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

box-shadow draws the shadow of the element’s box, so a transparent PNG gets a rectangular shadow. filter: drop-shadow follows the alpha channel and casts a shadow of the actual shape, which is what you want for an icon or for text. drop-shadow has no spread parameter and costs more to paint.

Why does my blurred image have soft edges?

Because a blur affects the element’s boundary as well as its contents — there is nothing beyond the edge to blur with, so it fades out. Put the image in a container with overflow: hidden, and the container will clip the soft edge away.

Why did a positioned child move when I added a filter?

Any filter other than none creates a containing block for fixed and absolutely positioned descendants, just as transform does. A child positioned against the viewport is now positioned against the filtered element instead. Move the filter to a different element, or reposition the child.

Are CSS filters good for performance?

They composite on the GPU and are cheap to apply, and animating opacity, brightness or saturation is fine. Blur is the exception: it forces a re-rasterisation each frame, so animating a large blur can drop frames on mobile. Test it on a real device rather than a desktop.

Can I use a filter on a background image only?

Not with filter, which applies to the whole element including its text. Use backdrop-filter to affect what is behind an element, or put the background on its own absolutely positioned child and filter that.

Related tools

See all developer tools →