Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

color-interpolation — SVG color interpolation space

color-interpolation selects the space used to calculate intermediate SVG colors. It is inherited and initially sRGB; the example compares two gradients with identical endpoint colors.

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

Syntax

color-interpolation: auto | sRGB | linearRGB | <color-interpolation-method>;

color-interpolation is an inherited SVG property whose initial value is sRGB. Its own animation type is discrete. For gradients, set it on the gradient element: styles do not inherit from the shape referencing the gradient through fill.

sRGB interpolates encoded components, linearRGB interpolates components proportional to light intensity, and auto leaves the choice to the browser. In SVG, the property selects the color space for gradient interpolation, alpha compositing, and color animation with animate. It does not set the color interpolation space for CSS Transitions or CSS Animations. Filters have a separate property, color-interpolation-filters.

The current draft also permits <color-interpolation-method>, for example in oklab; the property index still lists only the three older keywords. A draft definition does not establish browser support.

The example uses href to share stops between two horizontal black-to-white gradients. SVG specifies a lighter midpoint for the lower gradient (linearRGB) than for the upper gradient (sRGB). In Chromium, the two may look identical: Chromium can report linearRGB as the computed value for the lower gradient without using it to interpolate the gradient stops. To check the result, save the code as HTML and check rendering and computed values on #encoded and #linear in the target browser, including Chromium 152 when verifying that scope. Parsing alone does not confirm rendering.

Examples

<!doctype html>
<meta charset="utf-8">
<title>color-interpolation</title>
<svg xmlns="http://www.w3.org/2000/svg" width="320" height="100" viewBox="0 0 320 100">
  <style>
    #encoded { color-interpolation: sRGB; }
    #linear { color-interpolation: linearRGB; }
  </style>
  <defs>
    <linearGradient id="encoded">
      <stop offset="0" stop-color="black"/>
      <stop offset="1" stop-color="white"/>
    </linearGradient>
    <linearGradient id="linear" href="#encoded"/>
  </defs>
  <rect width="320" height="45" fill="url(#encoded)"/>
  <rect y="55" width="320" height="45" fill="url(#linear)"/>
</svg>

Result

Two horizontal black-to-white gradients. SVG specifies a lighter midpoint for the lower gradient (`linearRGB`) than for the upper gradient (`sRGB`). In Chromium, the gradients may look identical even when the computed value for the lower gradient is `linearRGB`, because Chromium can report that value without using it to interpolate the gradient stops.

Compare the midpoints: SVG specifies a lighter midpoint for the lower gradient (`linearRGB`) than for the upper one (`sRGB`), but Chromium may render them identically even when the lower gradient’s computed value is `linearRGB`.

Sources