CSS filter Property
The filter property applies graphical effects such as blurring, color adjustments, and shadows to the rendered appearance of an element.
Filters can modify images, text, backgrounds, and other rendered content without changing the original source. Multiple filter functions can be combined, and the order in which they appear determines how the effects are applied.
filter Syntax
The filter property accepts none or a space-separated list of filter functions and SVG filter references.
Basic Syntax
selector {
filter: blur(5px);
}
Single Filter
.image {
filter: grayscale(100%);
}
Multiple Filters
.image {
filter: brightness(110%) contrast(120%) saturate(130%);
}
SVG Filter Reference
.image {
filter: url("#custom-filter");
}
No Filter
.image {
filter: none;
}
CSS-Wide Keywords
.image {
filter: inherit;
}
.image {
filter: initial;
}
.image {
filter: unset;
}
.image {
filter: revert;
}
.image {
filter: revert-layer;
}
The initial value is none, meaning no filter effects are applied.
Property Values
The filter property supports predefined filter functions, SVG filter references, and the keyword none.
| Value | Description |
|---|---|
none |
Applies no filter effects. This is the initial value. |
blur() |
Applies a Gaussian blur. |
brightness() |
Adjusts the brightness of the rendered content. |
contrast() |
Adjusts the difference between light and dark areas. |
drop-shadow() |
Creates a shadow based on the rendered shape and its transparency. |
grayscale() |
Converts colors toward shades of gray. |
hue-rotate() |
Rotates colors around the hue circle. |
invert() |
Inverts colors. |
opacity() |
Adjusts the transparency of the rendered content. |
saturate() |
Adjusts color saturation. |
sepia() |
Applies a warm, sepia-toned color effect. |
url() |
References an SVG filter definition. |
CSS-Wide Values
| Value | Description |
|---|---|
inherit |
Uses the computed filter value of the parent element. |
initial |
Restores the initial value, none. |
unset |
Restores the initial value because the property is not inherited. |
revert |
Reverts the property according to the CSS cascade origins. |
revert-layer |
Reverts the property according to the CSS cascade layers. |
Property Characteristics
| Characteristic | Value |
|---|---|
| Initial value | none |
| Inherited | No |
| Applies to | All elements, with SVG-specific exclusions |
| Computed value | As specified, with URLs made absolute |
| Animation type | Filter function list, with compatible functions interpolated |
| Percentages | Accepted by several filter functions |
Each filter function has its own accepted values and units. The filter property itself does not accept a standalone number or percentage.
How It Works
The browser renders an element and its descendants, then applies the specified filter effects to the resulting graphical content before compositing it into the page.
Step 1: Select an Element
<img class="filtered-image" src="example.jpg" alt="Sample landscape">
Step 2: Apply a Filter
.filtered-image {
filter: grayscale(100%);
}
The image appears in grayscale without changing the original image file.
Step 3: Combine Effects
.filtered-image {
filter: grayscale(100%) contrast(120%);
}
The browser first applies grayscale, then increases the contrast of the grayscale result.
Step 4: Remove the Effects
.filtered-image {
filter: none;
}
The image returns to its normal appearance.
Important Distinction
Filters change the rendered appearance of content. They do not permanently edit image files, modify HTML content, or change the element's layout dimensions.
Filter Functions
CSS provides several built-in functions for common visual effects. Each function accepts parameters that determine the strength or appearance of the effect.
| Function | Example | Effect |
|---|---|---|
blur() |
blur(4px) |
Softens edges and details |
brightness() |
brightness(150%) |
Increases brightness |
contrast() |
contrast(150%) |
Increases contrast |
drop-shadow() |
drop-shadow(4px 4px 5px #555) |
Adds a shadow |
grayscale() |
grayscale(100%) |
Removes color saturation |
hue-rotate() |
hue-rotate(90deg) |
Changes hues |
invert() |
invert(100%) |
Inverts colors |
opacity() |
opacity(50%) |
Reduces opacity |
saturate() |
saturate(200%) |
Increases saturation |
sepia() |
sepia(100%) |
Applies a sepia effect |
Most filter functions accept optional arguments. When an argument is omitted, the function uses its defined default value.
blur()
The blur() function applies a Gaussian blur to the rendered content.
Syntax
.image {
filter: blur(5px);
}
Examples
.slight-blur {
filter: blur(2px);
}
.medium-blur {
filter: blur(5px);
}
.strong-blur {
filter: blur(12px);
}
How It Works
The length determines the standard deviation of the Gaussian blur. Larger values generally produce a softer, more blurred appearance.
Important Consideration
The value must be a nonnegative length. Percentages are not accepted by blur().
See the CSS blur() Function reference for additional details.
brightness()
The brightness() function adjusts the brightness of the rendered content.
Syntax
.image {
filter: brightness(150%);
}
Examples
.dark-image {
filter: brightness(50%);
}
.normal-image {
filter: brightness(100%);
}
.bright-image {
filter: brightness(150%);
}
How It Works
A value of 100% leaves brightness unchanged. Values below 100% darken the content, while values above 100% increase brightness.
Important Consideration
A value of 0% produces black output for the filtered color content. Negative values are not allowed.
See the CSS brightness() Function reference for additional details.
contrast()
The contrast() function adjusts the difference between light and dark areas of rendered content.
Syntax
.image {
filter: contrast(150%);
}
Examples
.low-contrast {
filter: contrast(50%);
}
.normal-contrast {
filter: contrast(100%);
}
.high-contrast {
filter: contrast(180%);
}
How It Works
A value of 100% leaves contrast unchanged. Lower values reduce contrast, while higher values increase it.
Important Consideration
A value of 0% produces a uniform gray result for opaque content. Negative values are not allowed.
See the CSS contrast() Function reference for additional details.
grayscale()
The grayscale() function converts colors toward shades of gray.
Syntax
.image {
filter: grayscale(100%);
}
Examples
.original-image {
filter: grayscale(0%);
}
.partial-grayscale {
filter: grayscale(50%);
}
.full-grayscale {
filter: grayscale(100%);
}
How It Works
A value of 0% leaves colors unchanged, while 100% converts the rendered colors to grayscale.
Important Consideration
Values above 100% are clamped to the maximum grayscale effect. Negative values are not allowed.
See the CSS grayscale() Function reference for additional details.
hue-rotate()
The hue-rotate() function applies a hue rotation to the rendered colors.
Syntax
.image {
filter: hue-rotate(90deg);
}
Examples
.small-hue-shift {
filter: hue-rotate(45deg);
}
.medium-hue-shift {
filter: hue-rotate(180deg);
}
.full-hue-rotation {
filter: hue-rotate(360deg);
}
How It Works
The function applies a color transformation based on the specified angle. A value of 0deg leaves colors unchanged.
Important Consideration
The function uses a color matrix transformation, so the results are not always identical to directly rotating HSL hue values.
See the CSS hue-rotate() Function reference for additional details.
invert()
The invert() function reverses the color values of rendered content.
Syntax
.image {
filter: invert(100%);
}
Examples
.original-colors {
filter: invert(0%);
}
.partial-inversion {
filter: invert(50%);
}
.full-inversion {
filter: invert(100%);
}
How It Works
A value of 0% leaves colors unchanged. A value of 100% fully inverts the colors.
Important Consideration
At 50%, opaque colors become a uniform middle gray. Values above 100% are clamped for the effect.
See the CSS invert() Function reference for additional details.
opacity()
The opacity() filter function adjusts the transparency of rendered content.
Syntax
.image {
filter: opacity(50%);
}
Examples
.fully-visible {
filter: opacity(100%);
}
.semi-transparent {
filter: opacity(50%);
}
.fully-transparent {
filter: opacity(0%);
}
How It Works
A value of 100% preserves the original opacity, while 0% makes the filtered content fully transparent.
opacity() vs. opacity Property
The opacity() function operates as part of the filter effects pipeline. The standalone opacity property controls the opacity of the element's composited rendering.
Important Consideration
The two approaches can produce similar visible results, but they differ in how they participate in rendering and interact with other effects.
See the CSS opacity() Function reference for additional details.
saturate()
The saturate() function adjusts the intensity of colors in rendered content.
Syntax
.image {
filter: saturate(200%);
}
Examples
.desaturated-image {
filter: saturate(30%);
}
.normal-saturation {
filter: saturate(100%);
}
.vivid-image {
filter: saturate(200%);
}
How It Works
A value of 100% leaves saturation unchanged. Lower values reduce saturation, while higher values increase it.
Important Consideration
A value of 0% produces grayscale output. Values above 100% are permitted, but the resulting colors may be clipped by the output color range.
See the CSS saturate() Function reference for additional details.
sepia()
The sepia() function applies a warm, brownish color transformation to rendered content.
Syntax
.image {
filter: sepia(100%);
}
Examples
.original-image {
filter: sepia(0%);
}
.partial-sepia {
filter: sepia(50%);
}
.full-sepia {
filter: sepia(100%);
}
How It Works
A value of 0% leaves the original colors unchanged. A value of 100% applies the full sepia effect.
Important Consideration
Values above 100% are clamped to the maximum sepia effect. Negative values are not allowed.
See the CSS sepia() Function reference for additional details.
drop-shadow()
The drop-shadow() function creates a shadow based on the alpha shape of the rendered content.
Syntax
.image {
filter: drop-shadow(5px 5px 8px #555);
}
Examples
.small-shadow {
filter: drop-shadow(2px 2px 3px rgb(0 0 0 / 30%));
}
.medium-shadow {
filter: drop-shadow(5px 5px 8px rgb(0 0 0 / 40%));
}
.offset-shadow {
filter: drop-shadow(10px 4px 0 #336699);
}
How It Works
The first two lengths specify horizontal and vertical offsets. An optional third length controls the blur radius, and an optional color determines the shadow color.
drop-shadow() vs. box-shadow
The drop-shadow() function follows the transparency of the rendered content, while box-shadow is based on the element's CSS box.
Important Consideration
Unlike box-shadow, drop-shadow() does not accept a spread radius or the inset keyword.
See the CSS drop-shadow() Function reference for additional details.
SVG Filters
The filter property can reference SVG filter definitions for effects that go beyond the built-in CSS filter functions.
SVG Filter Definition
<svg width="0" height="0" aria-hidden="true">
<defs>
<filter id="custom-blur">
<feGaussianBlur stdDeviation="4"/>
</filter>
</defs>
</svg>
CSS Reference
.filtered-image {
filter: url("#custom-blur");
}
How It Works
The url() function identifies an SVG filter element. The browser applies the filter primitives defined inside that element.
Common SVG Filter Primitives
| Primitive | Purpose |
|---|---|
feGaussianBlur |
Applies a Gaussian blur. |
feColorMatrix |
Transforms color channels. |
feOffset |
Offsets graphical content. |
feBlend |
Blends two graphical inputs. |
feComposite |
Combines graphical inputs using compositing operations. |
Important Consideration
SVG filters can be more flexible than built-in CSS functions, but their filter regions and rendering costs require additional attention.
Combining Multiple Filters
Multiple filter functions can be applied by listing them in a single filter declaration, separated by spaces.
Basic Combination
.image {
filter: grayscale(100%) contrast(120%);
}
Color Adjustments
.image {
filter: brightness(110%) saturate(140%) contrast(105%);
}
Blur and Shadow
.image {
filter: blur(2px) drop-shadow(5px 5px 6px #555);
}
Order Matters
.example-one {
filter: drop-shadow(5px 5px 6px #555) blur(2px);
}
.example-two {
filter: blur(2px) drop-shadow(5px 5px 6px #555);
}
Filter functions are applied from left to right. The first declaration blurs the result after adding the shadow, while the second adds a shadow after blurring the content.
Replacing a Filter List
.image {
filter: grayscale(100%);
}
.image:hover {
filter: brightness(120%);
}
The hover declaration replaces the original filter list rather than adding to it.
Important Consideration
To preserve existing effects when changing a filter state, include all desired functions in the new declaration.
filter vs. backdrop-filter
The filter and backdrop-filter properties apply graphical effects to different rendered content.
filter
.image {
filter: blur(5px);
}
Applies the blur to the element's own rendered content, including its descendants.
backdrop-filter
.overlay {
background-color: rgb(255 255 255 / 30%);
backdrop-filter: blur(5px);
}
Applies the blur to the content visible behind the element.
Comparison
| Behavior | filter | backdrop-filter |
|---|---|---|
| Primary target | Element's rendered content | Backdrop behind the element |
| Common use | Image and content effects | Frosted-glass overlays |
| Blur effect | Blurs the element | Blurs the backdrop |
| Requires visible backdrop | No | Yes, for a visible backdrop effect |
Important Consideration
For a frosted-glass effect, use backdrop-filter with a transparent or partially transparent background. Applying filter: blur() to the overlay would blur the overlay itself.
Animations and Transitions
The filter property supports transitions and animations for compatible filter function lists.
Hover Transition
.interactive-image {
filter: grayscale(100%);
transition: filter 0.3s ease;
}
.interactive-image:hover {
filter: grayscale(0%);
}
Brightness Transition
.interactive-image {
filter: brightness(100%);
transition: filter 0.3s ease;
}
.interactive-image:hover {
filter: brightness(130%);
}
Keyframe Animation
.animated-image {
animation: brightness-pulse 2s ease-in-out infinite alternate;
}
@keyframes brightness-pulse {
from {
filter: brightness(100%);
}
to {
filter: brightness(140%);
}
}
Multiple Animated Filters
.animated-image {
animation: color-shift 3s ease-in-out infinite alternate;
}
@keyframes color-shift {
from {
filter: saturate(100%) hue-rotate(0deg);
}
to {
filter: saturate(180%) hue-rotate(90deg);
}
}
Reduced Motion
@media (prefers-reduced-motion: reduce) {
.animated-image {
animation: none;
}
.interactive-image {
transition: none;
}
}
Important Consideration
Compatible filter functions can interpolate smoothly. Incompatible function lists, or certain SVG filter references, may cause transitions to behave discretely instead.
filter Example
This example demonstrates several filter effects applied to the same SVG graphic. Each example uses identical source content, allowing the visual differences to be compared.
HTML Example
<div class="filter-demo">
<figure>
<svg class="original" viewBox="0 0 160 110" role="img" aria-label="Original colored graphic">
<rect width="160" height="110" fill="#f1f5f9"/>
<circle cx="55" cy="55" r="32" fill="#e67e22"/>
<rect x="80" y="25" width="55" height="60" rx="8" fill="#336699"/>
</svg>
<figcaption>Original</figcaption>
</figure>
<figure>
<svg class="grayscale" viewBox="0 0 160 110" role="img" aria-label="Graphic with grayscale filter">
<rect width="160" height="110" fill="#f1f5f9"/>
<circle cx="55" cy="55" r="32" fill="#e67e22"/>
<rect x="80" y="25" width="55" height="60" rx="8" fill="#336699"/>
</svg>
<figcaption>grayscale(100%)</figcaption>
</figure>
<figure>
<svg class="sepia" viewBox="0 0 160 110" role="img" aria-label="Graphic with sepia filter">
<rect width="160" height="110" fill="#f1f5f9"/>
<circle cx="55" cy="55" r="32" fill="#e67e22"/>
<rect x="80" y="25" width="55" height="60" rx="8" fill="#336699"/>
</svg>
<figcaption>sepia(100%)</figcaption>
</figure>
<figure>
<svg class="invert" viewBox="0 0 160 110" role="img" aria-label="Graphic with inverted colors">
<rect width="160" height="110" fill="#f1f5f9"/>
<circle cx="55" cy="55" r="32" fill="#e67e22"/>
<rect x="80" y="25" width="55" height="60" rx="8" fill="#336699"/>
</svg>
<figcaption>invert(100%)</figcaption>
</figure>
</div>
CSS Example
.filter-demo {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
gap: 20px;
}
.filter-demo figure {
margin: 0;
text-align: center;
}
.filter-demo svg {
display: block;
width: 100%;
max-width: 160px;
margin: 0 auto;
}
.filter-demo .grayscale {
filter: grayscale(100%);
}
.filter-demo .sepia {
filter: sepia(100%);
}
.filter-demo .invert {
filter: invert(100%);
}
.filter-demo figcaption {
margin-top: 8px;
font-size: 0.9rem;
}
The original graphic retains its colors. The grayscale version removes color, the sepia version applies warm tones, and the inverted version reverses the colors.
All four examples use the same SVG shapes. The differences come entirely from the CSS filter property.
Accessibility
CSS filters can change the visibility, contrast, and color relationships of rendered content. These changes should not make important information difficult to perceive.
Maintain Sufficient Contrast
Filters such as brightness(), contrast(), and opacity() can reduce readability. Check the final rendered appearance against the surrounding background.
Do Not Rely on Color Alone
Color adjustments should not be the only way to communicate important states or information.
Avoid Blurring Essential Content
Do not apply strong blur effects to text, controls, or other information visitors need to read or interact with.
Provide Text Alternatives
Informative images should retain meaningful alternative text even when visual filters are applied.
Interactive States
If filters are used for hover or focus effects, ensure that keyboard users receive an equivalent indication where appropriate.
Reduced Motion
Avoid rapid flashing or distracting filter animations. Respect the prefers-reduced-motion media query when motion effects are not essential.
Important Consideration
Filters are visual effects, not substitutes for accessible content structure, readable text, or clear interaction feedback.
Important Considerations
Keep the following points in mind when using filter:
- Purpose: Applies graphical effects to rendered content.
- Initial value:
none. - Inheritance: The property is not inherited.
- Descendants: A filter applied to an element affects its rendered content, including descendants.
- Multiple functions: Filter functions are separated by spaces.
- Order: Functions are applied from left to right.
- Replacement: A new
filterdeclaration replaces the previous filter list. - blur(): Applies a Gaussian blur.
- brightness(): Adjusts brightness.
- contrast(): Adjusts contrast.
- grayscale(): Removes color saturation.
- hue-rotate(): Applies a hue transformation.
- invert(): Inverts colors.
- opacity(): Adjusts transparency within the filter pipeline.
- saturate(): Adjusts color saturation.
- sepia(): Applies a sepia color transformation.
- drop-shadow(): Creates a shadow based on rendered transparency.
- SVG filters: Custom effects can be referenced using
url(). - Animations: Compatible filter functions can transition smoothly.
- Performance: Complex filters, especially large blurs and animated effects, can increase rendering costs.
- Layout: Filters do not change an element's layout dimensions, although effects may extend beyond its visual bounds.
- Stacking context: A computed value other than
nonecreates a stacking context. - Positioned descendants: A filtered element generally establishes a containing block for absolutely and fixed-positioned descendants, except when the filter applies to the document root.
- Accessibility: Ensure that visual effects do not reduce readability or hide essential information.
Use the filter property for visual adjustments and effects that should remain separate from the original content. Keep filter combinations purposeful and test their appearance across different backgrounds and display sizes.
Browser Support
The CSS filter property is Widely available and supported by modern browsers, including Chrome, Edge, Firefox, and Safari.
Built-in CSS filter functions have broad support. More complex SVG filter references and specific animation combinations may require additional testing.
Supported Example
.image {
filter: grayscale(100%) contrast(120%);
}
Feature Detection
@supports (filter: blur(5px)) {
.image {
filter: blur(5px);
}
}
Fallback Example
.image {
opacity: 0.8;
}
@supports (filter: grayscale(100%)) {
.image {
opacity: 1;
filter: grayscale(100%);
}
}
The fallback provides a basic visual adjustment when the filter declaration is unsupported. It does not reproduce the grayscale effect.
Compatibility Considerations
Modern browsers generally support the standard, unprefixed filter property. Older browser versions may have limited support or require vendor-prefixed implementations.
For current compatibility information, visit Can I Use? .
Specifications
The filter property is defined in the Filter Effects Module Level 1, which describes CSS filter functions, SVG filter references, and the rendering behavior of graphical effects.
Filter Effects Module Level 1: filter Property
The specification also defines the built-in filter functions and their parameters.
Filter Effects Module Level 1: Filter Functions
These specifications describe filter syntax, processing order, interpolation, and interactions with SVG filters.
