CSS stop-color Property

The CSS stop-color property specifies the color of an individual stop within an SVG linear or radial gradient.

Each gradient stop defines a color at a particular position. The browser interpolates colors between stops to create smooth transitions. The stop-color property controls the color, while the SVG offset attribute controls the stop's position.

stop-color Syntax

The stop-color property accepts a CSS color value or a CSS-wide keyword.

Basic Syntax

stop {
  stop-color: blue;
}

Common Values

stop {
  stop-color: red;
}
stop {
  stop-color: #2563eb;
}
stop {
  stop-color: rgb(37 99 235);
}
stop {
  stop-color: hsl(220 83% 53%);
}
stop {
  stop-color: currentColor;
}
stop {
  stop-color: transparent;
}

CSS-Wide Keywords

stop {
  stop-color: initial;
}
stop {
  stop-color: inherit;
}
stop {
  stop-color: unset;
}
stop {
  stop-color: revert;
}
stop {
  stop-color: revert-layer;
}

Unlike the CSS background property, stop-color does not accept a gradient function such as linear-gradient(). It specifies one color for one SVG gradient stop.

Property Values

Value Description
<color> Specifies the gradient stop color using a valid CSS color value.
currentColor Uses the computed value of the element's color property.
transparent Specifies a fully transparent color.
initial Resets the property to black.
inherit Uses the computed value from the parent element.
unset Resets the property to black because it is not inherited.
revert Reverts the property according to CSS cascade origin rules.
revert-layer Reverts the property according to CSS cascade layer rules.

Property Characteristics

Characteristic Value
Initial value black
Inherited No
Applies to SVG <stop> elements
Computed value Computed color
Animation type By computed value type (color)
Percentages Not applicable as a standalone property value
Related property stop-opacity
Specification SVG 2

Valid Examples

stop {
  stop-color: navy;
}
stop {
  stop-color: #0d9488;
}
stop {
  stop-color: rgb(13 148 136);
}
stop {
  stop-color: hsl(174 84% 32%);
}
stop {
  stop-color: rgb(255 0 0 / 50%);
}
stop {
  stop-color: currentColor;
}

Invalid Examples

stop {
  stop-color: 50%;
}
stop {
  stop-color: 10px;
}
stop {
  stop-color: linear-gradient(red, blue);
}
stop {
  stop-color: red blue;
}
stop {
  stop-color: auto;
}

The property accepts a single valid color value. Lengths, standalone percentages, multiple colors, and CSS gradient functions are not valid values.

How It Works

SVG gradients are defined using <lineargradient> or <radialgradient> elements. Inside each gradient, one or more <stop> elements establish colors at specific positions.

Step 1: Define a Gradient

<lineargradient id="exampleGradient">
  <stop offset="0%"/>
  <stop offset="100%"/>
</lineargradient>

The gradient contains two stops positioned at the beginning and end.

Step 2: Assign Stop Colors

#exampleGradient stop:first-child {
  stop-color: #2563eb;
}
#exampleGradient stop:last-child {
  stop-color: #0d9488;
}

The first stop is blue, and the second stop is teal.

Step 3: Apply the Gradient

<rect width="200" height="100" fill="url(#exampleGradient)"/>

The rectangle uses the gradient as its fill. The browser interpolates between the specified stop colors.

Complete SVG Example

<svg viewBox="0 0 200 100" role="img" aria-label="Blue to teal gradient">
  <defs>
    <lineargradient id="exampleGradient">
      <stop offset="0%" stop-color="#2563eb"/>
      <stop offset="100%" stop-color="#0d9488"/>
    </lineargradient>
  </defs>
  <rect width="200" height="100" fill="url(#exampleGradient)"/>
</svg>

Understanding offset

The SVG offset attribute controls where each stop appears along the gradient. Common values include 0%, 50%, and 100%.

The stop-color property controls the color at that position, not the position itself.

Linear Gradients

An SVG linear gradient transitions between colors along a straight line.

Two-Color Linear Gradient

<lineargradient id="linearExample">
  <stop offset="0%" stop-color="#2563eb"/>
  <stop offset="100%" stop-color="#0d9488"/>
</lineargradient>

The browser blends blue into teal between the two stops.

Three-Color Linear Gradient

<lineargradient id="threeColorGradient">
  <stop offset="0%" stop-color="#2563eb"/>
  <stop offset="50%" stop-color="#a855f7"/>
  <stop offset="100%" stop-color="#ec4899"/>
</lineargradient>

Adding a middle stop creates two color transitions: blue to purple and purple to pink.

Horizontal Gradient

<lineargradient id="horizontalGradient" x1="0%" y1="0%" x2="100%" y2="0%">
  <stop offset="0%" stop-color="#2563eb"/>
  <stop offset="100%" stop-color="#0d9488"/>
</lineargradient>

Vertical Gradient

<lineargradient id="verticalGradient" x1="0%" y1="0%" x2="0%" y2="100%">
  <stop offset="0%" stop-color="#2563eb"/>
  <stop offset="100%" stop-color="#0d9488"/>
</lineargradient>

Diagonal Gradient

<lineargradient id="diagonalGradient" x1="0%" y1="0%" x2="100%" y2="100%">
  <stop offset="0%" stop-color="#2563eb"/>
  <stop offset="100%" stop-color="#0d9488"/>
</lineargradient>

Important Consideration

Gradient direction is controlled by the SVG gradient coordinates, not by stop-color. Changing stop colors does not change the gradient's direction.

Radial Gradients

An SVG radial gradient transitions between colors outward from a focal region toward the edge of a circle or ellipse.

Basic Radial Gradient

<radialgradient id="radialExample">
  <stop offset="0%" stop-color="#facc15"/>
  <stop offset="100%" stop-color="#ea580c"/>
</radialgradient>

The gradient transitions from yellow near the center to orange near the outer boundary.

Three-Color Radial Gradient

<radialgradient id="threeStopRadial">
  <stop offset="0%" stop-color="#ffffff"/>
  <stop offset="50%" stop-color="#38bdf8"/>
  <stop offset="100%" stop-color="#1d4ed8"/>
</radialgradient>

Multiple stops create more detailed transitions between the center and outer edge.

Changing the Gradient Center

<radialgradient id="offsetRadial" cx="30%" cy="30%" r="70%">
  <stop offset="0%" stop-color="#ffffff"/>
  <stop offset="100%" stop-color="#2563eb"/>
</radialgradient>

The cx, cy, and r attributes control the gradient geometry.

Important Consideration

The stop-color property works the same way for linear and radial gradients. The gradient element determines how the colors are distributed.

Supported Color Values

The stop-color property supports CSS color syntax, including named colors, hexadecimal colors, functional color notation, and special color keywords.

Named Colors

stop {
  stop-color: coral;
}

Hexadecimal Colors

stop {
  stop-color: #2563eb;
}

RGB Colors

stop {
  stop-color: rgb(37 99 235);
}

HSL Colors

stop {
  stop-color: hsl(220 83% 53%);
}

Colors With Alpha Transparency

stop {
  stop-color: rgb(37 99 235 / 50%);
}

The alpha component contributes to the stop's transparency.

currentColor

.gradient-icon {
  color: #2563eb;
}
.gradient-icon stop {
  stop-color: currentColor;
}

The stop uses the current computed text color of the SVG stop element, which can be inherited from an ancestor.

transparent

stop {
  stop-color: transparent;
}

The stop uses a fully transparent color.

Modern Color Functions

stop {
  stop-color: oklch(60% 0.18 250);
}

Modern CSS color functions may be used where the browser supports them.

Important Consideration

Support for individual color functions can differ from support for the stop-color property itself. Test newer color syntax when targeting older browsers.

Using stop-opacity

The stop-opacity property controls the opacity of an SVG gradient stop independently of its color.

Opaque Stop

stop {
  stop-color: #2563eb;
  stop-opacity: 1;
}

The stop is fully opaque.

Partially Transparent Stop

stop {
  stop-color: #2563eb;
  stop-opacity: 0.5;
}

The stop contributes a blue color with 50% opacity.

Fully Transparent Stop

stop {
  stop-color: #2563eb;
  stop-opacity: 0;
}

The stop contributes no visible opacity at its position.

Gradient With Transparency

<lineargradient id="fadeGradient">
  <stop offset="0%" stop-color="#2563eb" stop-opacity="1"/>
  <stop offset="100%" stop-color="#2563eb" stop-opacity="0"/>
</lineargradient>

The gradient fades from opaque blue to transparent blue.

Color Alpha vs. stop-opacity

stop {
  stop-color: rgb(37 99 235 / 50%);
  stop-opacity: 0.5;
}

Both alpha transparency and stop-opacity contribute to the resulting opacity. In this example, the effective stop opacity is approximately 25%.

Important Consideration

Use stop-color to select the color and stop-opacity to control additional transparency. They can be used together.

CSS Property vs. SVG Attribute

SVG supports stop-color as both a CSS property and a presentation attribute.

SVG Presentation Attribute

<stop offset="0%" stop-color="#2563eb"/>

The color is declared directly on the SVG stop element.

CSS Property

<stop class="gradient-start" offset="0%"/>
.gradient-start {
  stop-color: #2563eb;
}

The color is controlled through a stylesheet.

CSS Cascade

SVG presentation attributes participate in the CSS cascade with lower priority than ordinary author CSS declarations.

CSS Override Example

<stop class="gradient-start" offset="0%" stop-color="red"/>
.gradient-start {
  stop-color: blue;
}

The stylesheet declaration overrides the presentation attribute, so the stop becomes blue.

Important Consideration

Use presentation attributes for simple self-contained SVG markup or CSS declarations when colors need to be reused, updated, or animated through stylesheets.

Animating Gradient Colors

Because stop-color is a color property, it can be animated between compatible color values.

CSS Transition

.gradient-start {
  stop-color: #2563eb;
  transition: stop-color 0.5s ease;
}
.gradient-icon:hover .gradient-start {
  stop-color: #ec4899;
}

When the gradient is used by an SVG shape, hovering over the SVG can transition the stop color from blue to pink.

CSS Keyframe Animation

@keyframes gradient-color-change {
  0% {
    stop-color: #2563eb;
  }
  50% {
    stop-color: #a855f7;
  }
  100% {
    stop-color: #0d9488;
  }
}
.animated-stop {
  animation: gradient-color-change 4s ease-in-out infinite;
}

The stop color changes continuously between blue, purple, and teal.

Reduced Motion

@media (prefers-reduced-motion: reduce) {
  .animated-stop {
    animation: none;
  }
}

Respect reduced-motion preferences when gradient animations are decorative rather than essential.

Important Consideration

CSS transitions and animations require the SVG gradient to be rendered in a context where its stop colors can update. Test the animation in the browsers you support.

Practical Examples

Two-Color Gradient

.gradient-start {
  stop-color: #2563eb;
}
.gradient-end {
  stop-color: #0d9488;
}

Defines the starting and ending colors of a gradient.

Three-Color Gradient

.gradient-start {
  stop-color: #2563eb;
}
.gradient-middle {
  stop-color: #a855f7;
}
.gradient-end {
  stop-color: #ec4899;
}

Creates a gradient with three color stops.

Gradient Using currentColor

.gradient-icon {
  color: #2563eb;
}
.gradient-icon .gradient-start {
  stop-color: currentColor;
}
.gradient-icon .gradient-end {
  stop-color: white;
}

Allows the starting gradient color to follow the element's current color.

Transparent Gradient

.fade-start {
  stop-color: #2563eb;
  stop-opacity: 1;
}
.fade-end {
  stop-color: #2563eb;
  stop-opacity: 0;
}

Creates a fade from opaque blue to transparent blue.

Hover Color Change

.gradient-icon .gradient-start {
  stop-color: #2563eb;
  transition: stop-color 0.3s ease;
}
.gradient-icon:hover .gradient-start {
  stop-color: #ec4899;
}

Changes the starting gradient color when the SVG is hovered.

Dark Theme Gradient

.gradient-start {
  stop-color: #2563eb;
}
.gradient-end {
  stop-color: #0d9488;
}
@media (prefers-color-scheme: dark) {
  .gradient-start {
    stop-color: #60a5fa;
  }
  .gradient-end {
    stop-color: #2dd4bf;
  }
}

Adjusts the gradient colors for dark color schemes.

Resetting a Stop Color

.gradient-start {
  stop-color: initial;
}

Resets the stop color to the initial value, black.

stop-color Example

This example displays three SVG gradients. Each gradient uses different stop-color values to produce a distinct color transition.

HTML Example

<div class="stop-color-demo">
  <svg viewBox="0 0 600 300" role="img" aria-label="Three gradient examples: blue to teal, blue to purple to pink, and yellow to orange">
    <defs>
      <lineargradient id="stopdemolinear1" x1="0%" y1="0%" x2="100%" y2="0%">
        <stop class="blue-stop" offset="0%"/>
        <stop class="teal-stop" offset="100%"/>
      </lineargradient>
      <lineargradient id="stopdemolinear2" x1="0%" y1="0%" x2="100%" y2="0%">
        <stop class="blue-stop" offset="0%"/>
        <stop class="purple-stop" offset="50%"/>
        <stop class="pink-stop" offset="100%"/>
      </lineargradient>
      <radialgradient id="stopDemoRadial">
        <stop class="yellow-stop" offset="0%"/>
        <stop class="orange-stop" offset="100%"/>
      </radialgradient>
    </defs>
    <rect x="20" y="20" width="560" height="65" rx="10" fill="url(#stopdemolinear1)"/>
    <rect x="20" y="115" width="560" height="65" rx="10" fill="url(#stopdemolinear2)"/>
    <rect x="20" y="210" width="560" height="65" rx="10" fill="url(#stopDemoRadial)"/>
  </svg>
</div>

CSS Example

.stop-color-demo svg {
  display: block;
  width: 100%;
  height: auto;
}
.stop-color-demo .blue-stop {
  stop-color: #2563eb;
}
.stop-color-demo .teal-stop {
  stop-color: #0d9488;
}
.stop-color-demo .purple-stop {
  stop-color: #a855f7;
}
.stop-color-demo .pink-stop {
  stop-color: #ec4899;
}
.stop-color-demo .yellow-stop {
  stop-color: #facc15;
}
.stop-color-demo .orange-stop {
  stop-color: #ea580c;
}
Browser Result

The first rectangle uses two colors, the second uses three colors, and the third uses a radial gradient. Each transition is controlled by the colors assigned to its SVG stops.

Comparing the Gradients

Gradient Stops Color Transition
Linear 1 2 Blue to teal
Linear 2 3 Blue to purple to pink
Radial 2 Yellow to orange

Changing the First Gradient

.stop-color-demo .blue-stop {
  stop-color: #dc2626;
}

Changes the blue stops to red in the gradients that use the blue-stop class.

Changing the Middle Stop

.stop-color-demo .purple-stop {
  stop-color: #facc15;
}

Changes the middle stop in the second gradient from purple to yellow.

Adding Transparency

.stop-color-demo .teal-stop {
  stop-opacity: 0.4;
}

Reduces the opacity of the teal stop in the first gradient.

Accessibility Considerations

SVG gradients can enhance visual presentation, but their colors should not reduce readability or become the only means of communicating information.

Maintain Sufficient Contrast

When text or important symbols appear over a gradient, verify contrast across the entire gradient rather than checking only the starting and ending colors.

Avoid Color-Only Communication

Do not rely solely on gradient colors to distinguish statuses, categories, or values. Provide labels or other visual indicators.

Provide Accessible SVG Names

Informative SVG graphics should include an accessible name or equivalent text description.

<svg viewBox="0 0 200 100" role="img" aria-label="Blue to teal gradient">
  <!-- SVG gradient content -->
</svg>

Decorative SVG Graphics

Purely decorative SVG graphics can use aria-hidden="true" to avoid unnecessary announcements.

Avoid Distracting Animations

Rapid or continuous gradient color changes can be distracting. Use restrained animation and respect reduced-motion preferences.

Test Different Color Schemes

Verify that gradient colors remain distinguishable and readable in light and dark themes.

Consider Color Vision Differences

Choose gradient colors that remain useful when viewers have difficulty distinguishing particular hues.

Common Mistakes

Applying stop-color to the Gradient Element

lineargradient {
  stop-color: red;
}

The property applies to SVG <stop> elements. Because it is not inherited, assigning it to the gradient container does not set the colors of its child stops.

Confusing stop-color With fill

The fill property controls the paint used to fill an SVG shape. The stop-color property controls a color within a gradient.

Using a Gradient Function as a Color

stop {
  stop-color: linear-gradient(red, blue);
}

CSS gradient functions are not valid stop-color values.

Forgetting the offset Attribute

The offset attribute establishes where each stop occurs. Without appropriate offsets, the gradient may not produce the intended transition.

Using Invalid Color Values

stop {
  stop-color: 25px;
}

The property requires a valid CSS color value.

Expecting Inheritance

The property is not inherited. Set colors on individual stop elements or target multiple stops with CSS selectors.

Confusing stop-opacity With opacity

The stop-opacity property controls a gradient stop's transparency, while the opacity property affects the composited appearance of an SVG element or group.

Forgetting to Reference the Gradient

Defining gradient stops does not automatically display the gradient. An SVG shape must reference the gradient through a paint property such as fill or stroke.

Using Duplicate Gradient IDs

Gradient IDs should be unique within the document to prevent incorrect references.

Assuming Color Functions Have Universal Support

Modern color functions may require compatibility testing even when the browser supports SVG gradients.

Important Considerations

Keep the following points in mind when using stop-color:

  • It defines the color of an SVG gradient stop.
  • The initial value is black.
  • The property is not inherited.
  • It applies to SVG <stop> elements.
  • It accepts valid CSS color values.
  • It supports currentColor and transparent.
  • It can use alpha transparency within supported color functions.
  • It works with both linear and radial SVG gradients.
  • The SVG offset attribute determines stop positions.
  • The browser interpolates colors between gradient stops.
  • Multiple stops can create complex color transitions.
  • The property can be declared through CSS or SVG presentation attributes.
  • Ordinary author CSS declarations can override SVG presentation attributes.
  • It is distinct from the fill and stroke properties.
  • Use stop-opacity for additional stop transparency.
  • Color values can be animated where supported.
  • Gradient IDs should be unique within the document.
  • Gradient definitions must be referenced by an SVG paint property to become visible.
  • Modern color syntax may have different browser compatibility requirements.
  • Maintain sufficient contrast when gradients appear behind text or important graphics.
  • Test gradient appearance across supported browsers and display devices.

Browser Support

The CSS stop-color property is widely supported for SVG gradient stops in modern browsers, including Chrome, Edge, Firefox, and Safari.

Basic named colors, hexadecimal colors, RGB colors, and other established CSS color formats are broadly supported. Newer color functions may have different compatibility requirements.

For current compatibility information, visit Can I Use? and search for stop-color.

Feature Detection

@supports (stop-color: #2563eb) {
  .gradient-start {
    stop-color: #2563eb;
  }
}

Feature queries can test whether a browser recognizes the property and specified color syntax.

Fallback Behavior

If a stop-color declaration is unsupported or invalid, the browser ignores it. The stop then uses another applicable cascade value or the initial value, black.

Testing Recommendations

Test gradient colors, transparency, CSS overrides, animations, and newer color functions in the browsers you support.

Specifications

The stop-color property is defined in the SVG 2 specification.

SVG 2 - stop-color Property

The specification defines how gradient stop colors contribute to SVG paint server rendering.

For additional documentation and examples, consult MDN Web Docs.

MDN Web Docs: stop-color