CKTIS / CSS
stop-color — SVG gradient stop color
The CSS `stop-color` property specifies the color of a `stop` element in an SVG gradient. It sets neither the stop position nor the shape’s color directly.
Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required
Syntax
stop-color: <color>;stop-color specifies the color of a gradient stop represented by a stop element inside linearGradient or radialGradient. The separate offset attribute sets its position; a shape uses the gradient through fill or stroke.
Its value is a <color>, such as red, #ff0000, or currentColor. The initial value is black. The property is not inherited and can be animated. A CSS declaration can override a stop-color presentation attribute on the same element.
currentColor refers to the stop element’s color value. The color’s alpha is multiplied by stop-opacity. Warning: transparent means transparent black; to fade a color without transitioning toward black, keep that color and set the final stop-opacity: 0.
In the example, CSS rules set a red start and a blue end for the gradient. The expected result is a 240 × 80 rectangle with a horizontal transition from red on the left to blue on the right.
Examples
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Set SVG gradient colors with stop-color</title>
<style>
#start { stop-color: #ff0000; }
#end { stop-color: #0000ff; }
</style>
</head>
<body>
<figure>
<svg width="240" height="80" viewBox="0 0 240 80" role="img" aria-labelledby="gradient-title">
<title id="gradient-title">Rectangle with a horizontal gradient</title>
<defs>
<linearGradient id="gradient" x1="0%" y1="0%" x2="100%" y2="0%">
<stop id="start" offset="0%" />
<stop id="end" offset="100%" />
</linearGradient>
</defs>
<rect width="240" height="80" fill="url(#gradient)" />
</svg>
<figcaption id="result"></figcaption>
</figure>
<script>
const colorNames = { 'rgb(255, 0, 0)': 'red', 'rgb(0, 0, 255)': 'blue' };
function stopColor(id) {
const color = getComputedStyle(document.getElementById(id)).getPropertyValue('stop-color');
return colorNames[color] ?? color;
}
const result = `Rectangle gradient: ${stopColor('start')} on the left to ${stopColor('end')} on the right.`;
document.getElementById('result').textContent = result;
console.log(result);
</script>
</body>
</html>Result
Rectangle gradient: red on the left to blue on the right.
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.