Support0

CSS filter playground

Explore filter by enabling multiple functions at once, adjust their values, and test the result on an image or a color background before copying the generated CSS.

Ask AI

CSS filter playground

Response generated with openai/gpt-5.4-nano. AI can make mistakes. Always review the result.
HTML
<div class="filter-demo" role="img" aria-label="Filtered image"></div>
Tailwind CSS
Examples for Tailwind CSS 4.3 with the default theme. Custom values keep arbitrary classes when there is no equivalent utility. Changing the theme can change utility values.
<div class="min-block-80 bg-[url(https://baselinelab.dev/baseline-wordmark.png)] bg-center bg-contain bg-no-repeat blur-xs" role="img" aria-label="Filtered image"></div>
CSS
.filter-demo {
  min-block-size: 20rem;
  background-image: url("https://baselinelab.dev/baseline-wordmark.png");
  background-position: center;
  background-size: contain;
  background-repeat: no-repeat;
  filter: blur(4px);
}

Educational guide to filter

How to compose CSS filters

Understand which pixels filter changes, how function order affects the result, and when to use a shadow that follows transparency. Examples are independent of the playground.

Mental model

Think of an image of the already painted element: a chain of operations transforms its pixels before compositing them onto the page.

  1. Painted element

    Content, background, border, and descendants.

  2. Function chain

    Each operation receives the previous result.

  3. Visual result

    Appearance changes without recalculating the box space.

From boxes to pixelsStatic conceptual diagram: filter transforms the painted group. It does not modify the image file or DOM text.

Not inherited, but grouped

The initial value is none and the property is not inherited. Filtering a container still affects its children’s content: everything is painted as a group before applying the effect.

The effect does not reserve space

Blur and shadows may extend outside the box, but filter does not change layout. Leave enough space and check container overflow to avoid clipping.

filter changes the element’s own pixels, including text and borders. backdrop-filter acts behind the surface. To soften an illustration while keeping text readable, apply filter only to the illustration.

Filter the group or only the image

Filter on the container

This text should stay readable.

Filter only on the SVG

This text should stay readable.

The first card blurs its circle, text, border, and background. In the second, only the circle has blur; the text and box stay sharp. External labels are not filtered.
Filter the group or only the image
<div class="filter-guide-scope">
  <div>
    <p>Filter on the container</p>
    <div class="filter-guide-group">
      <svg viewBox="0 0 120 120" aria-hidden="true">
        <circle cx="60" cy="60" r="34" fill="none" stroke-width="18" />
      </svg>
      <p>This text should stay readable.</p>
    </div>
  </div>
  <div>
    <p>Filter only on the SVG</p>
    <div class="filter-guide-image">
      <svg viewBox="0 0 120 120" aria-hidden="true">
        <circle cx="60" cy="60" r="34" fill="none" stroke-width="18" />
      </svg>
      <p>This text should stay readable.</p>
    </div>
  </div>
</div>
:root {
  color-scheme: light dark;
}

.filter-guide-scope {
  display: flex;
  flex-wrap: wrap;
  gap: 2rem;

  > div {
    flex: 1 1 12rem;
    min-inline-size: 0;
    display: grid;
    align-content: start;
    gap: 1rem;
  }

  svg {
    display: block;
    inline-size: min(100%, 7.5rem);
    block-size: auto;
    margin-inline: auto;
    overflow: visible;
  }

  circle {
    stroke: light-dark(oklch(0.88 0.09 66), oklch(0.78 0.22 66));
  }

  p {
    margin: 0;
    color: light-dark(oklch(0.22 0.01 95), oklch(0.95 0.01 95));
    font: 1rem/1.6 system-ui, sans-serif;
    overflow-wrap: anywhere;
  }

  .filter-guide-group,
  .filter-guide-image {
    display: grid;
    gap: 1rem;
    padding: 1rem;
    border: 1px solid light-dark(oklch(0.84 0.01 95), oklch(0.36 0.024 260));
    background: light-dark(color-mix(in oklch, oklch(0.95 0.008 95) 98%, white), color-mix(in oklch, oklch(0.22 0.024 260) 86%, black));
  }

  .filter-guide-group {
    filter: blur(2px);
  }

  .filter-guide-image svg {
    filter: blur(2px);
  }
}

Functions and values

Separate the list with spaces, not commas. These are the playground’s ten functions, grouped by the change they produce.

Light and contrast

brightness(110%) contrast(118%)

100% equals 1 and leaves the result unchanged. brightness(0) turns pixels black and contrast(0) makes them gray. Both accept values above 100%; increasing contrast does not guarantee accessible text contrast.

Saturation and hue

saturate(150%) hue-rotate(90deg)

saturate(100%) is neutral; 0% removes saturation and values above 100% increase it. hue-rotate() takes an angle, with 0deg as its neutral value. It uses a color matrix, not an HSL adjustment that exactly preserves lightness and saturation.

Grayscale, inversion, and sepia

grayscale(100%) invert(0%) sepia(0%)

For these three functions, 0% is neutral and 100% applies the full conversion. Values above 100% are clamped to 100%; they add no intensity. Use grayscale to desaturate, invert to invert channels, and sepia for a warm finish.

Transparency

opacity(60%)

opacity(100%) preserves alpha and 0% makes the result transparent; values above 100% are clamped to 100%. Inside filter, its position in the chain can affect a later shadow. The CSS opacity property acts separately; its effect combines with the filter.

Blur and shadow

blur(2px) drop-shadow(8px 8px 0 blue)

blur() takes a nonnegative length, without percentages; 0px is neutral. drop-shadow() accepts two offsets, an optional nonnegative blur length, and a color. Offsets may be negative. It accepts neither inset nor spread.

Neutral values preserve appearance, but blur(0) is not equivalent to filter: none for stacking and positioning. Specify arguments: some empty functions, such as grayscale(), apply the full effect rather than the neutral value.

Order changes the result

CSS applies functions from left to right. The output of an operation, including a newly created shadow, enters the next one.

With grayscale → drop-shadow, the circle becomes gray first and then gains a blue shadow. Reversing the chain to drop-shadow → grayscale also turns the shadow gray. Both lists use the same values.

The same functions in reverse order

Reference: no filter

1. grayscale → 2. drop-shadow

1. drop-shadow → 2. grayscale

Reference: an orange circle with no filter. Second case: a gray circle with a blue shadow. Third case: gray circle and shadow. Text describes the difference alongside color.
The same functions in reverse order
<div class="filter-guide-order">
  <div>
    <p>Reference: no filter</p>
    <svg viewBox="0 0 120 120" aria-hidden="true">
      <circle cx="60" cy="60" r="34" fill="none" stroke-width="18" />
    </svg>
  </div>
  <div>
    <p>1. grayscale → 2. drop-shadow</p>
    <svg class="filter-guide-shadow-last" viewBox="0 0 120 120" aria-hidden="true">
      <circle cx="60" cy="60" r="34" fill="none" stroke-width="18" />
    </svg>
  </div>
  <div>
    <p>1. drop-shadow → 2. grayscale</p>
    <svg class="filter-guide-gray-last" viewBox="0 0 120 120" aria-hidden="true">
      <circle cx="60" cy="60" r="34" fill="none" stroke-width="18" />
    </svg>
  </div>
</div>
:root {
  color-scheme: light dark;
}

.filter-guide-order {
  display: flex;
  flex-wrap: wrap;
  gap: 2rem;

  > div {
    flex: 1 1 12rem;
    min-inline-size: 0;
    display: grid;
    align-content: start;
    gap: 1rem;
  }

  svg {
    display: block;
    inline-size: min(100%, 7.5rem);
    block-size: auto;
    margin-inline: auto;
    overflow: visible;
  }

  circle {
    stroke: light-dark(oklch(0.88 0.09 66), oklch(0.78 0.22 66));
  }

  p {
    margin: 0;
    color: light-dark(oklch(0.22 0.01 95), oklch(0.95 0.01 95));
    font: 1rem/1.6 system-ui, sans-serif;
    overflow-wrap: anywhere;
  }

  .filter-guide-shadow-last {
    filter: grayscale(100%) drop-shadow(8px 8px 0 light-dark(oklch(0.87 0.1 261), oklch(0.78 0.24 261)));
  }

  .filter-guide-gray-last {
    filter: drop-shadow(8px 8px 0 light-dark(oklch(0.87 0.1 261), oklch(0.78 0.24 261))) grayscale(100%);
  }
}

Two filter declarations do not add effects: the cascade winner replaces the other. Write the complete chain in one declaration. You can repeat a function; to change order here, edit the copied CSS. The playground serializes functions in a fixed order.

Practical example

A card with a monochrome illustration and sharp text: the filter belongs to the SVG, not the container.

The recipe combines contrast(118%) grayscale(100%) using the lab’s function generator. Replace the SVG with your illustration or an image with an appropriate alt, and keep text outside the filtered element.

Monochrome illustration, unfiltered text

A monochrome illustration accompanies this unfiltered text.

The circle loses its color and receives a moderate contrast increase. The paragraph keeps the theme colors and is outside the chain.
Monochrome illustration, unfiltered text
<div class="filter-guide-recipe">
  <svg viewBox="0 0 120 120" aria-hidden="true">
    <circle cx="60" cy="60" r="34" fill="none" stroke-width="18" />
  </svg>
  <p>A monochrome illustration accompanies this unfiltered text.</p>
</div>
:root {
  color-scheme: light dark;
}

.filter-guide-recipe {
  display: grid;
  gap: 1rem;
  padding: 1rem;
  border: 1px solid light-dark(oklch(0.84 0.01 95), oklch(0.36 0.024 260));
  background: light-dark(color-mix(in oklch, oklch(0.95 0.008 95) 98%, white), color-mix(in oklch, oklch(0.22 0.024 260) 86%, black));

  svg {
    display: block;
    inline-size: min(100%, 7.5rem);
    block-size: auto;
    margin-inline: auto;
    overflow: visible;
  }

  circle {
    stroke: light-dark(oklch(0.88 0.09 66), oklch(0.78 0.22 66));
  }

  p {
    margin: 0;
    color: light-dark(oklch(0.22 0.01 95), oklch(0.95 0.01 95));
    font: 1rem/1.6 system-ui, sans-serif;
    overflow-wrap: anywhere;
  }

  svg {
    filter: contrast(118%) grayscale(100%);
  }
}

The examples’ SVG is decorative and hidden with aria-hidden. If an image conveys information, retain its text alternative. A visual filter alone cannot communicate a state or securely hide content.

drop-shadow() versus box-shadow

Choose what casts the shadow: the box or pixels with alpha. With an opaque rectangular image, the difference can be less obvious.

box-shadow follows the SVG’s rectangular box, including empty areas. drop-shadow() uses the painted result’s alpha: it follows the circle and preserves its hole. Adding an opaque background to the filtered element makes that background part of the silhouette too.

A transparent shape with a hole

box-shadow

drop-shadow()

The box shadow draws an offset rectangle. The filter shadow follows the ring. Both use 8px offsets and zero blur to isolate the shape difference.
A transparent shape with a hole
<div class="filter-guide-shadows">
  <div>
    <p>box-shadow</p>
    <svg class="filter-guide-box" viewBox="0 0 120 120" aria-hidden="true">
      <circle cx="60" cy="60" r="34" fill="none" stroke-width="18" />
    </svg>
  </div>
  <div>
    <p>drop-shadow()</p>
    <svg class="filter-guide-drop" viewBox="0 0 120 120" aria-hidden="true">
      <circle cx="60" cy="60" r="34" fill="none" stroke-width="18" />
    </svg>
  </div>
</div>
:root {
  color-scheme: light dark;
}

.filter-guide-shadows {
  display: flex;
  flex-wrap: wrap;
  gap: 2rem;

  > div {
    flex: 1 1 12rem;
    min-inline-size: 0;
    display: grid;
    align-content: start;
    gap: 1rem;
  }

  svg {
    display: block;
    inline-size: min(100%, 7.5rem);
    block-size: auto;
    margin-inline: auto;
    overflow: visible;
  }

  circle {
    stroke: light-dark(oklch(0.88 0.09 66), oklch(0.78 0.22 66));
  }

  p {
    margin: 0;
    color: light-dark(oklch(0.22 0.01 95), oklch(0.95 0.01 95));
    font: 1rem/1.6 system-ui, sans-serif;
    overflow-wrap: anywhere;
  }

  .filter-guide-box {
    box-shadow: 8px 8px 0 light-dark(oklch(0.87 0.1 261), oklch(0.78 0.24 261));
  }

  .filter-guide-drop {
    filter: drop-shadow(8px 8px 0 light-dark(oklch(0.87 0.1 261), oklch(0.78 0.24 261)));
  }
}
drop-shadow(8px 8px 4px blue)

The third drop-shadow() length specifies the standard deviation of Gaussian blur, whereas box-shadow uses a blur radius: the same number should not be expected to look identical. For multiple filter shadows, chain drop-shadow() calls; later calls receive the previous result, including its shadows.

Common mistakes

Identify what is painted, which declaration wins, and where the result is clipped.

Text gets blurred too

Expected result
Change the image while keeping text sharp.
Cause
The filter is on a container that includes both image and text.
Solution
Move filter to the visual element. To filter the background behind a panel, explore backdrop-filter.

An effect disappears when another is added

Expected result
Keep blur and grayscale together.
Cause
Two filter declarations compete in the cascade; they do not accumulate.
Solution
Use a complete list, such as filter: blur(2px) grayscale(100%), and check its order.

The chain does not apply

Expected result
See every effect from a valid declaration.
Cause
A comma between functions, a blur percentage, or an unsupported function invalidates the whole declaration.
Solution
Separate with spaces, check units, and simplify one function at a time. The browser keeps the valid cascade winner.

The shadow is still rectangular

Expected result
Follow the image’s transparent silhouette.
Cause
The image or filtered element’s background has opaque alpha across the whole box.
Solution
Use a transparent asset and apply drop-shadow to the appropriate element without an opaque background.

The shadow or blur is clipped

Expected result
See the full effect without covering nearby content.
Cause
The effect reserves no space and an ancestor may clip it with overflow.
Solution
Leave space and inspect clipping. Do not remove necessary overflow without checking the layout.

Support and compatibility

CSS filter functions are widely available. The card shows the feature’s Baseline status independently of the visible result in this browser.

Examples use native CSS functions and render without JavaScript. filter also accepts url() to reference SVG filters, outside these recipes’ scope; the overall status does not prove support for every resource, context, or SVG detail.

A computed value other than none, even blur(0), creates a stacking context. Except on the root element, it also establishes a containing block for absolute and fixed descendants. Filtering a large wrapper may change overlays and their relationship with z-index.

Cost depends on the painted area, radius, chain, and updates. Keep filters on small surfaces and measure on real devices before animating large areas. Avoid assuming free acceleration or adding permanent will-change. These recipes add no motion.