Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

saturate(): change saturation of the rendered image

Apply a color-matrix filter to painted content without changing its layout or source colors.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required

Syntax

filter: saturate(200%);

In filter, saturate() adjusts the saturation of the rendered input. The argument is a nonnegative number or percentage: 0 removes saturation, 1 or 100% leaves colors unchanged, and values above 100% increase the effect. An omitted argument defaults to 1. A negative argument is invalid; it does not invert the effect.

This is a matrix operation on RGB channels, not an edit of the saturation component in an HSL color. It need not preserve the original hue or lightness, and channels can be clipped at their limits. Applied to an element, the filter affects its painted content, including descendants, without rearranging layout or rewriting the original image file and CSS color declarations. It does not provide a new color value for the color property.

The example actually rasterizes a rectangle colored 120,80,40 and reads its pixels. In Chromium 157, 0 gives the gray 86,86,86; 1 and an omitted argument preserve 120,80,40; 200% gives 154,74,0. Alpha remains 255 in these opaque samples. The blue channel reaches its lower limit, illustrating why stronger saturation is not a simple percentage increase of each channel. The negative syntax check returns false.

Examples

const pixel=async amount=>{const svg='<svg xmlns="http://www.w3.org/2000/svg" width="8" height="8"><rect width="8" height="8" fill="rgb(120,80,40)" style="filter:saturate('+amount+')"/></svg>';const image=new Image();image.src='data:image/svg+xml;charset=utf-8,'+encodeURIComponent(svg);await image.decode();const canvas=document.createElement('canvas');canvas.width=canvas.height=8;const ctx=canvas.getContext('2d');ctx.drawImage(image,0,0);return [...ctx.getImageData(4,4,1,1).data].join(',')};
for(const amount of ['0','1','200%',''])console.log((amount||'omitted')+'='+await pixel(amount));
console.log('negative='+CSS.supports('filter','saturate(-1)'));

Result

0=86,86,86,255
1=120,80,40,255
200%=154,74,0,255
omitted=120,80,40,255
negative=false

These are sampled rendered pixels, not merely accepted CSS declarations. Exact integer channels reflect rasterization and rounding in the recorded browser; the identity and grayscale relationships are the essential checks.

Sources