CSS color-interpolation Property
The color-interpolation property specifies the color space used for certain SVG color interpolation operations.
It controls how colors are blended between SVG gradient stops and during applicable SVG graphical operations. The available values are auto, sRGB, and linearRGB, each affecting how intermediate colors are calculated.
This property is primarily associated with SVG rendering. It does not control ordinary CSS background gradients, CSS transitions, or CSS animations. For interpolation inside SVG filter effects, use the related color-interpolation-filters property.
color-interpolation Syntax
The color-interpolation property accepts three values that determine the color space used for supported SVG interpolation operations.
selector {
color-interpolation: sRGB;
}
General Syntax
selector {
color-interpolation: auto | sRGB | linearRGB;
}
Automatic Color Interpolation
.svg-gradient {
color-interpolation: auto;
}
sRGB Color Interpolation
.svg-gradient {
color-interpolation: sRGB;
}
Linear RGB Color Interpolation
.svg-gradient {
color-interpolation: linearRGB;
}
SVG Presentation Attribute
<linearGradient id="example-gradient" color-interpolation="linearRGB">
<stop offset="0%" stop-color="red"></stop>
<stop offset="100%" stop-color="blue"></stop>
</linearGradient>
CSS-Wide Keywords
.svg-gradient {
color-interpolation: inherit;
}
.svg-gradient {
color-interpolation: initial;
}
.svg-gradient {
color-interpolation: unset;
}
.svg-gradient {
color-interpolation: revert;
}
.svg-gradient {
color-interpolation: revert-layer;
}
Property Values
The property provides three values for selecting the color interpolation behavior.
| Value | Description |
|---|---|
auto |
Allows the user agent to select the interpolation color space. For SVG color interpolation, this generally produces sRGB behavior. |
sRGB |
Performs interpolation in the standard sRGB color space using gamma-encoded channel values. |
linearRGB |
Performs interpolation in linear-light RGB, where channel values are proportional to light intensity. |
CSS-Wide Keywords
| Value | Description |
|---|---|
inherit |
Uses the computed value from the parent element. |
initial |
Resets the property to sRGB. |
unset |
Uses the inherited value because the property is inherited. |
revert |
Reverts the property according to cascade origin rules. |
revert-layer |
Reverts the property according to cascade layer rules. |
Property Characteristics
| Characteristic | Value |
|---|---|
| Initial value | sRGB |
| Inherited | Yes |
| Applies to | SVG graphics and applicable SVG paint operations |
| Computed value | As specified |
| Animation type | Discrete |
| Percentages | Not applicable |
| Primary use | Controlling SVG color interpolation |
The property does not accept an arbitrary color-space name. Use one of the three supported values.
How It Works
Color interpolation calculates intermediate colors between two or more specified colors. The selected color space affects the resulting colors.
Step 1: Define Two Colors
<stop offset="0%" stop-color="red"></stop>
<stop offset="100%" stop-color="blue"></stop>
Step 2: Choose a Color Space
.gradient-linear {
color-interpolation: linearRGB;
}
Step 3: Calculate Intermediate Colors
The browser converts the gradient colors into the selected interpolation color space and calculates the intermediate channel values.
Step 4: Render the Gradient
The resulting colors are converted as needed for display. The gradient may appear brighter or darker depending on the interpolation space.
Step 5: Compare the Results
With red and blue gradient stops, sRGB produces a relatively dark purple midpoint. The linearRGB value produces a brighter midpoint because the interpolation is performed using linear-light values.
The endpoint colors remain the same. The difference appears in the colors calculated between them.
auto Value
The auto value allows the browser to select an appropriate color interpolation space.
.svg-gradient {
color-interpolation: auto;
}
Automatic Selection
The user agent determines the interpolation behavior. In typical SVG rendering, auto produces results equivalent to sRGB.
SVG Example
<linearGradient id="auto-gradient" color-interpolation="auto">
<stop offset="0%" stop-color="red"></stop>
<stop offset="100%" stop-color="blue"></stop>
</linearGradient>
When to Use auto
Use auto when you do not need to specify a particular interpolation space and are comfortable with the browser's selected behavior.
Predictable Results
When consistent interpolation behavior is important, explicitly specify sRGB or linearRGB instead.
sRGB Value
The sRGB value performs interpolation using standard sRGB color channel values.
.svg-gradient {
color-interpolation: sRGB;
}
Standard RGB Interpolation
sRGB is the familiar color space used by traditional CSS hexadecimal and RGB colors.
Gradient Example
<linearGradient id="srgb-gradient" color-interpolation="sRGB">
<stop offset="0%" stop-color="#ff0000"></stop>
<stop offset="100%" stop-color="#0000ff"></stop>
</linearGradient>
Midpoint Behavior
For a red-to-blue gradient, interpolation in sRGB produces a midpoint near rgb(128 0 128).
Common Uses
Use sRGB when you want conventional RGB channel interpolation and predictable results consistent with traditional SVG gradients.
Initial Value
The initial value of color-interpolation is sRGB, so explicitly specifying it is generally unnecessary unless you need to override an inherited value.
linearRGB Value
The linearRGB value performs interpolation using linear-light RGB values rather than gamma-encoded sRGB channel values.
.svg-gradient {
color-interpolation: linearRGB;
}
Linear-Light Interpolation
In linear-light RGB, channel values correspond more directly to light intensity. This changes the appearance of intermediate colors.
Gradient Example
<linearGradient id="linear-gradient" color-interpolation="linearRGB">
<stop offset="0%" stop-color="#ff0000"></stop>
<stop offset="100%" stop-color="#0000ff"></stop>
</linearGradient>
Brighter Intermediate Colors
For red and blue endpoints, the midpoint is approximately rgb(188 0 188) when converted back to sRGB for display.
Comparison with sRGB
| Interpolation Space | Approximate Midpoint |
|---|---|
sRGB |
rgb(128 0 128) |
linearRGB |
rgb(188 0 188) |
When to Use linearRGB
Use linearRGB when linear-light blending produces the desired visual result, especially for gradients where the intermediate colors should appear brighter.
Linear-light interpolation is not automatically better for every design. The appropriate choice depends on the intended appearance.
Understanding Color Spaces
A color space defines how color values are represented and interpreted. The color-interpolation property selects between standard sRGB and linear-light RGB interpolation.
Gamma-Encoded sRGB
sRGB channel values are encoded nonlinearly. Interpolating these values directly produces different intermediate colors than interpolating physical light intensity.
Linear-Light RGB
Linear RGB values represent light intensity proportionally. Interpolating these values often produces brighter intermediate colors.
Visual Comparison
A gradient from red to blue demonstrates the difference clearly. The midpoint is darker in sRGB and brighter in linearRGB.
Same Endpoints
Both interpolation spaces use the same specified endpoint colors. Only the intermediate calculations differ.
Color Conversion
The browser performs the necessary conversions between the specified colors, the interpolation space, and the output color space.
Color Space Limitations
The property does not provide access to every modern CSS color space. Values such as oklab, oklch, and display-p3 are not valid values for color-interpolation.
For ordinary CSS gradients, use the interpolation syntax supported by the relevant CSS gradient function.
SVG Gradients
The color-interpolation property is commonly used to control the appearance of SVG gradients.
Linear Gradient
<svg width="300" height="100" viewBox="0 0 300 100">
<defs>
<linearGradient id="example-linear" color-interpolation="linearRGB">
<stop offset="0%" stop-color="red"></stop>
<stop offset="100%" stop-color="blue"></stop>
</linearGradient>
</defs>
<rect width="300" height="100" fill="url(#example-linear)"></rect>
</svg>
Radial Gradient
<svg width="200" height="200" viewBox="0 0 200 200">
<defs>
<radialGradient id="example-radial" color-interpolation="linearRGB">
<stop offset="0%" stop-color="white"></stop>
<stop offset="100%" stop-color="blue"></stop>
</radialGradient>
</defs>
<circle cx="100" cy="100" r="90" fill="url(#example-radial)"></circle>
</svg>
Multiple Gradient Stops
<linearGradient id="multi-gradient" color-interpolation="linearRGB">
<stop offset="0%" stop-color="red"></stop>
<stop offset="50%" stop-color="green"></stop>
<stop offset="100%" stop-color="blue"></stop>
</linearGradient>
The selected interpolation space affects the colors calculated between each pair of adjacent stops.
Gradient Reuse
An SVG gradient can be referenced by multiple SVG shapes. The gradient's interpolation behavior remains associated with the gradient definition.
CSS Styling
.custom-gradient {
color-interpolation: linearRGB;
}
Assign the class to the SVG gradient element to style its interpolation behavior through CSS.
SVG Presentation Attribute
SVG supports color-interpolation as a presentation attribute, allowing the interpolation space to be specified directly in SVG markup.
Attribute Syntax
<linearGradient id="example-gradient" color-interpolation="sRGB">
<stop offset="0%" stop-color="red"></stop>
<stop offset="100%" stop-color="blue"></stop>
</linearGradient>
CSS Equivalent
.example-gradient {
color-interpolation: sRGB;
}
CSS Cascade
When both a CSS declaration and an SVG presentation attribute specify the property, the CSS declaration takes precedence under normal cascade rules.
Inline SVG
Presentation attributes are convenient for self-contained SVG graphics, while CSS classes can simplify styling across multiple SVG elements.
Element Name Capitalization
SVG uses case-sensitive element names such as linearGradient and radialGradient. When SVG markup is embedded directly in an HTML document, lowercase spellings such as lineargradient and radialgradient are recognized by the HTML parser.
Standalone SVG documents use XML parsing and require the correct SVG capitalization.
Inheritance
The color-interpolation property is inherited, allowing SVG descendants to use a color interpolation setting established by an ancestor.
Parent Setting
.svg-graphic {
color-interpolation: linearRGB;
}
Child Override
.svg-graphic {
color-interpolation: linearRGB;
}
.svg-graphic .standard-gradient {
color-interpolation: sRGB;
}
Explicit Inheritance
.svg-gradient {
color-interpolation: inherit;
}
Reset to Initial Value
.svg-gradient {
color-interpolation: initial;
}
The initial keyword resets the property to sRGB.
Scope the Declaration
For predictable results, apply the property directly to the SVG gradient or relevant graphical element rather than relying on distant inherited styles.
color-interpolation vs. color-interpolation-filters
The color-interpolation and color-interpolation-filters properties both select interpolation spaces, but they apply to different SVG operations.
| Feature | color-interpolation | color-interpolation-filters |
|---|---|---|
| Primary purpose | Controls applicable SVG color interpolation, including gradients | Controls color processing in SVG filter primitives |
| Initial value | sRGB |
linearRGB |
| Values | auto, sRGB, linearRGB |
auto, sRGB, linearRGB |
| Inherited | Yes | Yes |
| Typical use | SVG gradient interpolation | SVG filter effects |
SVG Gradient Interpolation
.svg-gradient {
color-interpolation: linearRGB;
}
SVG Filter Interpolation
.svg-filter {
color-interpolation-filters: sRGB;
}
Different Defaults
The default for color-interpolation is sRGB, while the default for color-interpolation-filters is linearRGB.
Use the property that corresponds to the operation you want to control. Changing one does not automatically replace the behavior of the other.
CSS Gradients and Color Interpolation
Ordinary CSS gradients use their own interpolation syntax rather than the SVG color-interpolation property.
Standard CSS Gradient
.gradient {
background: linear-gradient(to right, red, blue);
}
Explicit sRGB Interpolation
.gradient {
background: linear-gradient(in srgb to right, red, blue);
}
Linear-Light RGB Interpolation
.gradient {
background: linear-gradient(in srgb-linear to right, red, blue);
}
OKLab Interpolation
.gradient {
background: linear-gradient(in oklab to right, red, blue);
}
OKLCH Interpolation
.gradient {
background: linear-gradient(in oklch to right, red, blue);
}
Important Difference
CSS gradient functions can specify interpolation spaces directly using the in syntax. The color-interpolation property does not change how these CSS gradients calculate their colors.
Modern CSS gradient interpolation syntax has its own browser compatibility requirements.
Practical Uses
The color-interpolation property is useful when an SVG graphic requires control over the appearance of intermediate colors.
Brighter SVG Gradients
.bright-gradient {
color-interpolation: linearRGB;
}
Linear-light interpolation can produce brighter intermediate colors between strongly contrasting endpoints.
Traditional SVG Gradients
.standard-gradient {
color-interpolation: sRGB;
}
Use sRGB when you want conventional RGB channel interpolation.
Reusable Gradient Styles
.svg-gradient-primary {
color-interpolation: linearRGB;
}
.svg-gradient-secondary {
color-interpolation: sRGB;
}
Radial Lighting Effects
Linear-light interpolation may be useful for SVG radial gradients intended to resemble changes in light intensity.
Vector Artwork
When working with SVG graphics exported from design software, changing the interpolation space can alter the appearance of gradients without changing their endpoint colors.
Comparing Color Blending
Use side-by-side SVG gradients to determine which interpolation space produces the intended visual result.
color-interpolation Example
The following example compares two SVG gradients with identical red and blue endpoints. The first uses sRGB, while the second uses linearRGB.
The difference is most visible near the center of each gradient.
<div class="color-interpolation-demo">
<div class="gradient-item">
<p>sRGB</p>
<svg viewBox="0 0 300 90" role="img" aria-label="Red to blue gradient using sRGB interpolation">
<defs>
<lineargradient id="demo-srgb" class="srgb-gradient">
<stop offset="0%" stop-color="red"></stop>
<stop offset="100%" stop-color="blue"></stop>
</lineargradient>
</defs>
<rect width="300" height="90" fill="url(#demo-srgb)"></rect>
</svg>
</div>
<div class="gradient-item">
<p>linearRGB</p>
<svg viewBox="0 0 300 90" role="img" aria-label="Red to blue gradient using linear RGB interpolation">
<defs>
<lineargradient id="demo-linear" class="linear-gradient">
<stop offset="0%" stop-color="red"></stop>
<stop offset="100%" stop-color="blue"></stop>
</lineargradient>
</defs>
<rect width="300" height="90" fill="url(#demo-linear)"></rect>
</svg>
</div>
</div>
.color-interpolation-demo {
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: 25px;
}
.color-interpolation-demo .gradient-item {
width: 300px;
max-width: 100%;
}
.color-interpolation-demo .gradient-item p {
margin-bottom: 8px;
font-weight: bold;
text-align: center;
}
.color-interpolation-demo svg {
display: block;
width: 100%;
height: auto;
}
.color-interpolation-demo .srgb-gradient {
color-interpolation: sRGB;
}
.color-interpolation-demo .linear-gradient {
color-interpolation: linearRGB;
}
sRGB
linearRGB
The sRGB gradient produces a darker purple midpoint, while the linearRGB gradient produces a brighter purple midpoint.
Both gradients use the same endpoint colors. The difference comes from the color space used to calculate the intermediate values.
Important Considerations
Keep the following points in mind when using color-interpolation:
- Purpose: Controls the color space used for applicable SVG interpolation operations.
- Initial value:
sRGB. - Inheritance: The property is inherited.
- Values: Supports
auto,sRGB, andlinearRGB. - auto: Allows the browser to select the interpolation color space.
- sRGB: Interpolates using gamma-encoded sRGB channel values.
- linearRGB: Interpolates using linear-light RGB values.
- SVG gradients: The property can affect linear and radial SVG gradients.
- Gradient endpoints: Changing the interpolation space does not change the specified endpoint colors.
- Intermediate colors: Different interpolation spaces can produce visibly different midpoint colors.
- SVG attributes: The property can be specified using an SVG presentation attribute.
- CSS cascade: CSS declarations override presentation attributes when applicable.
- Filter effects: Use
color-interpolation-filtersfor SVG filter primitives. - CSS gradients: The property does not control ordinary CSS gradient functions.
- Color spaces: Values such as
oklchanddisplay-p3are not accepted. - Animation: Changes between property values are discrete.
- Browser support: Test SVG interpolation behavior in the browsers relevant to your project.
Use color-interpolation when an SVG gradient or graphical operation requires a specific RGB interpolation behavior. For CSS gradients, use the interpolation syntax provided by the gradient function itself.
Browser Support
The color-interpolation property is supported in modern browsers for SVG rendering, including Chrome, Edge, Firefox, and Safari. Support and rendering behavior can vary by SVG operation.
It is an SVG-focused property rather than a general-purpose CSS property for controlling all color transitions or gradients.
SVG Gradient Example
.svg-gradient {
color-interpolation: linearRGB;
}
SVG Presentation Attribute
<linearGradient id="example-gradient" color-interpolation="linearRGB">
<stop offset="0%" stop-color="red"></stop>
<stop offset="100%" stop-color="blue"></stop>
</linearGradient>
Compatibility Considerations
When consistent gradient rendering is important, test the actual SVG graphic in your target browsers. The property should not be assumed to control CSS gradients, CSS animations, or SVG filter primitives.
For current compatibility information, visit Can I Use? and search for color-interpolation.
Specifications
The color-interpolation property is defined in SVG specifications, including SVG 2.
SVG 2 - color-interpolation Property
SVG 1.1 - color-interpolation Property
These specifications describe the available interpolation values and their behavior in SVG rendering.
