CSS stop-opacity Property

The CSS stop-opacity property controls the opacity of an individual color stop in an SVG linear or radial gradient.

It determines how transparent or opaque a gradient stop appears, allowing gradients to fade between different transparency levels. The property works alongside stop-color, which defines the color of each stop, and the SVG offset attribute, which determines its position.

stop-opacity Syntax

The stop-opacity property accepts a number or percentage representing the opacity of an SVG gradient stop.

Basic Syntax

stop {
  stop-opacity: 0.5;
}

Available Values

stop {
  stop-opacity: 0;
}
stop {
  stop-opacity: 0.25;
}
stop {
  stop-opacity: 0.5;
}
stop {
  stop-opacity: 0.75;
}
stop {
  stop-opacity: 1;
}
stop {
  stop-opacity: 50%;
}

CSS-Wide Keywords

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

The property accepts a single numeric or percentage value. Numbers between 0 and 1 represent transparency levels from fully transparent to fully opaque.

Property Values

Value Description
<number> Specifies opacity using a numeric value. Values are clamped to the range from 0 to 1 for rendering.
<percentage> Specifies opacity as a percentage, where 0% is fully transparent and 100% is fully opaque.
initial Resets the property to 1.
inherit Uses the computed value from the parent element.
unset Resets the property to 1 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 1
Inherited No
Applies to SVG <stop> elements
Computed value Specified number or percentage
Animation type By computed value type
Percentages Relative to an opacity value of 1
Related property stop-color
Specification SVG 2

Valid Values

stop {
  stop-opacity: 0;
}
stop {
  stop-opacity: 0.4;
}
stop {
  stop-opacity: 1;
}
stop {
  stop-opacity: 40%;
}
stop {
  stop-opacity: calc(0.25 + 0.25);
}

Invalid Values

stop {
  stop-opacity: auto;
}
stop {
  stop-opacity: 10px;
}
stop {
  stop-opacity: transparent;
}
stop {
  stop-opacity: half;
}
stop {
  stop-opacity: 0.5 1;
}

Color keywords, lengths, unsupported identifiers, and multiple opacity values are invalid. Use a number, percentage, or supported CSS calculation.

How It Works

SVG gradients are created using <lineargradient> or <radialGradient> elements. Each gradient contains <stop> elements that define colors and transparency levels at specific positions.

Step 1: Define a Gradient

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

Both stops use the same blue color.

Step 2: Set Different Opacity Values

#fadeExample stop:first-child {
  stop-opacity: 1;
}
#fadeExample stop:last-child {
  stop-opacity: 0;
}

The first stop is fully opaque, while the second is fully transparent.

Step 3: Apply the Gradient

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

The rectangle displays a gradient that fades from opaque blue to transparent blue.

Complete SVG Example

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

Understanding Transparency

The browser interpolates opacity between the gradient stops. If one stop has an opacity of 1 and another has an opacity of 0, the gradient gradually becomes transparent between them.

Background Visibility

Transparent areas reveal whatever is behind the SVG shape. The visible result therefore depends on the background or underlying content.

Understanding Opacity Values

Opacity values determine how much of a gradient stop's color contributes to the final rendered result.

Number Percentage Appearance
0 0% Fully transparent
0.25 25% 25% opaque
0.5 50% 50% opaque
0.75 75% 75% opaque
1 100% Fully opaque

Fully Opaque

stop {
  stop-opacity: 1;
}

The stop contributes its color without additional transparency from stop-opacity.

Partially Transparent

stop {
  stop-opacity: 0.5;
}

The stop contributes half of its available opacity.

Fully Transparent

stop {
  stop-opacity: 0;
}

The stop contributes no visible opacity at its position.

Values Outside the Normal Range

stop {
  stop-opacity: -0.5;
}
stop {
  stop-opacity: 1.5;
}

Out-of-range numeric values are accepted by the property syntax but are clamped to the valid opacity range for rendering. Negative values behave as fully transparent, while values greater than 1 behave as fully opaque.

Percentage Values

stop {
  stop-opacity: 50%;
}

The percentage 50% represents the same opacity as 0.5.

Linear Gradients

Linear gradients transition between colors and opacity levels along a straight line.

Opaque to Transparent

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

The gradient fades from fully opaque blue to transparent blue.

Transparent to Opaque

<lineargradient id="reverseFade">
  <stop offset="0%" stop-color="#0d9488" stop-opacity="0"/>
  <stop offset="100%" stop-color="#0d9488" stop-opacity="1"/>
</lineargradient>

The gradient gradually becomes visible from left to right when using the default horizontal direction.

Transparent Edges

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

The gradient is most opaque in the middle and transparent at both ends.

Partial Transparency

<lineargradient id="partialFade">
  <stop offset="0%" stop-color="#2563eb" stop-opacity="0.8"/>
  <stop offset="100%" stop-color="#0d9488" stop-opacity="0.3"/>
</lineargradient>

The gradient transitions between two colors while also changing opacity.

Important Consideration

The stop-opacity property controls transparency only. Gradient direction and stop positions are determined by the SVG gradient attributes.

Radial Gradients

Radial gradients can use different stop opacity values to create circular or elliptical fading effects.

Center to Transparent Edge

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

The gradient is opaque near the center and becomes transparent toward the outer edge.

Transparent Center

<radialGradient id="radialRing">
  <stop offset="0%" stop-color="#0d9488" stop-opacity="0"/>
  <stop offset="70%" stop-color="#0d9488" stop-opacity="1"/>
  <stop offset="100%" stop-color="#0d9488" stop-opacity="0"/>
</radialGradient>

The gradient creates a ring-like region with greater opacity away from the center.

Soft Highlight

<radialGradient id="softHighlight">
  <stop offset="0%" stop-color="#ffffff" stop-opacity="0.9"/>
  <stop offset="100%" stop-color="#ffffff" stop-opacity="0"/>
</radialGradient>

The gradient creates a soft white highlight that fades toward transparency.

Important Consideration

Radial gradients use the same stop-opacity values as linear gradients. The radial gradient's geometry determines how those opacity levels are distributed.

Using stop-color

The stop-color and stop-opacity properties work together to define the appearance of SVG gradient stops.

Color and Opacity

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

The gradient transitions from opaque blue to partially transparent teal.

Same Color, Different Opacity

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

Using the same color at both stops creates a fade without changing the hue.

Different Colors and Opacity

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

Each stop contributes both a color and an opacity level, producing a gradient that changes hue and transparency.

Important Consideration

The properties are independent. Changing stop-opacity does not change the declared stop-color value.

Alpha Transparency

CSS color functions can include an alpha component. When a gradient stop uses both color alpha and stop-opacity, their effects are multiplied.

Color With Alpha

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

The stop has an effective opacity of 50% because the color itself contains 50% alpha.

Additional stop-opacity

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

The effective opacity is approximately 25% because the color alpha and stop opacity are multiplied.

Opacity Calculation

The effective opacity is calculated as:

Effective opacity = Color alpha × stop-opacity

Examples

Color Alpha stop-opacity Effective Opacity
100% 1 100%
50% 1 50%
100% 0.5 50%
50% 0.5 25%
25% 0.5 12.5%

Choosing an Approach

Use stop-opacity when you want to adjust transparency independently of the stop color. Use color alpha when transparency is naturally part of the color definition.

Either approach can work, but avoid unintentionally reducing opacity twice.

CSS Property vs. SVG Attribute

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

SVG Presentation Attribute

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

The opacity is declared directly on the SVG stop element.

CSS Property

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

The opacity 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-opacity="1"/>
.gradient-start {
  stop-opacity: 0.3;
}

The stylesheet overrides the presentation attribute, giving the stop an opacity of 0.3.

Important Consideration

Use SVG presentation attributes for self-contained graphics or CSS declarations when opacity values need to be reused, updated, or animated.

Animating Stop Opacity

The stop-opacity property can be animated to create changing transparency effects within SVG gradients.

CSS Transition

.gradient-end {
  stop-opacity: 0.2;
  transition: stop-opacity 0.5s ease;
}
.gradient-icon:hover .gradient-end {
  stop-opacity: 1;
}

When the SVG is hovered, the ending stop becomes fully opaque.

CSS Keyframe Animation

@keyframes gradient-fade {
  0% {
    stop-opacity: 0.2;
  }
  50% {
    stop-opacity: 1;
  }
  100% {
    stop-opacity: 0.2;
  }
}
.animated-stop {
  animation: gradient-fade 3s ease-in-out infinite;
}

The stop repeatedly fades between low and high opacity.

Animating Multiple Stops

.gradient-start {
  animation: gradient-fade 3s ease-in-out infinite;
}
.gradient-end {
  animation: gradient-fade 3s ease-in-out infinite reverse;
}

The two stops animate in opposite directions, changing the gradient's transparency distribution.

Reduced Motion

@media (prefers-reduced-motion: reduce) {
  .animated-stop,
  .gradient-start,
  .gradient-end {
    animation: none;
    transition: none;
  }
}

Respect reduced-motion preferences when opacity animations are decorative.

Important Consideration

Gradient stop animations can behave differently depending on how SVG graphics are embedded and rendered. Test animations in the browsers you support.

Practical Examples

Fade to Transparency

.fade-start {
  stop-opacity: 1;
}
.fade-end {
  stop-opacity: 0;
}

Creates a gradient that gradually becomes transparent.

Fade From Transparency

.fade-start {
  stop-opacity: 0;
}
.fade-end {
  stop-opacity: 1;
}

Creates a gradient that gradually becomes opaque.

Soft Highlight

.highlight-start {
  stop-opacity: 0.8;
}
.highlight-end {
  stop-opacity: 0;
}

Creates a soft highlight that fades toward transparency.

Partially Transparent Gradient

.gradient-start {
  stop-opacity: 0.8;
}
.gradient-end {
  stop-opacity: 0.3;
}

Creates a gradient that remains partially transparent throughout.

Transparent Center

.radial-center {
  stop-opacity: 0;
}
.radial-middle {
  stop-opacity: 1;
}
.radial-edge {
  stop-opacity: 0;
}

Creates a radial gradient with a more opaque middle region.

Hover Fade

.gradient-icon .fade-end {
  stop-opacity: 0.2;
  transition: stop-opacity 0.3s ease;
}
.gradient-icon:hover .fade-end {
  stop-opacity: 1;
}

Changes the gradient's ending opacity on hover.

Resetting Opacity

.gradient-stop {
  stop-opacity: initial;
}

Restores the initial value of 1.

Percentage-Based Opacity

.gradient-stop {
  stop-opacity: 60%;
}

Sets the stop opacity to 60%.

stop-opacity Example

This example compares three SVG gradients with different opacity patterns. A checkerboard background makes the transparent areas easier to identify.

HTML Example

<div class="stop-opacity-demo">
  <svg viewBox="0 0 600 300" role="img" aria-label="Three blue gradients showing fade out, fade in, and transparent edges">
    <defs>
      <lineargradient id="opacityDemoFadeOut">
        <stop class="opaque-stop" offset="0%"/>
        <stop class="transparent-stop" offset="100%"/>
      </lineargradient>
      <lineargradient id="opacityDemoFadeIn">
        <stop class="transparent-stop" offset="0%"/>
        <stop class="opaque-stop" offset="100%"/>
      </lineargradient>
      <lineargradient id="opacityDemoCenter">
        <stop class="transparent-stop" offset="0%"/>
        <stop class="opaque-stop" offset="50%"/>
        <stop class="transparent-stop" offset="100%"/>
      </lineargradient>
    </defs>
    <rect x="20" y="20" width="560" height="65" rx="10" fill="url(#opacityDemoFadeOut)"/>
    <rect x="20" y="115" width="560" height="65" rx="10" fill="url(#opacityDemoFadeIn)"/>
    <rect x="20" y="210" width="560" height="65" rx="10" fill="url(#opacityDemoCenter)"/>
  </svg>
</div>

CSS Example

.stop-opacity-demo {
  background-color: #ffffff;
  background-image: linear-gradient(45deg, #e2e8f0 25%, transparent 25%), linear-gradient(-45deg, #e2e8f0 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #e2e8f0 75%), linear-gradient(-45deg, transparent 75%, #e2e8f0 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
}
.stop-opacity-demo svg {
  display: block;
  width: 100%;
  height: auto;
}
.stop-opacity-demo stop {
  stop-color: #2563eb;
}
.stop-opacity-demo .opaque-stop {
  stop-opacity: 1;
}
.stop-opacity-demo .transparent-stop {
  stop-opacity: 0;
}
Browser Result

The first gradient fades from opaque to transparent, the second fades from transparent to opaque, and the third is opaque in the center with transparent edges.

Comparing the Gradients

Gradient Opacity Pattern Result
Fade Out 1 to 0 Becomes transparent from left to right
Fade In 0 to 1 Becomes opaque from left to right
Center 0 to 1 to 0 Opaque center with transparent edges

Changing the Transparent Stops

.stop-opacity-demo .transparent-stop {
  stop-opacity: 0.3;
}

Changes the fully transparent stops to 30% opacity, making the gradients less transparent.

Changing the Opaque Stops

.stop-opacity-demo .opaque-stop {
  stop-opacity: 0.7;
}

Reduces the maximum stop opacity to 70%.

Changing the Gradient Color

.stop-opacity-demo stop {
  stop-color: #0d9488;
}

Changes all three gradients from blue to teal while preserving their opacity patterns.

Accessibility Considerations

Transparent gradients can affect the visibility of important SVG graphics and any content displayed over them.

Maintain Sufficient Contrast

When text or important symbols appear over a transparent gradient, verify contrast against the actual underlying background.

Avoid Transparency as the Only Indicator

Do not rely solely on differences in opacity to communicate status, selection, or meaning.

Consider Background Changes

Transparent gradient areas reveal underlying content. A gradient that appears clear over white may be difficult to distinguish over another background.

Provide Accessible SVG Names

Informative SVG graphics should include accessible names or equivalent text descriptions.

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

Decorative Graphics

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

Avoid Distracting Opacity Animations

Rapid or repeated changes in transparency can distract users. Keep animations restrained and respect reduced-motion preferences.

Test Different Themes

Verify that transparent gradients remain recognizable over light and dark backgrounds.

Test Zoom and Scaling

Ensure important SVG details remain visible when users zoom or resize the page.

Common Mistakes

Applying stop-opacity to the Gradient Element

lineargradient {
  stop-opacity: 0.5;
}

The property applies to SVG <stop> elements and is not inherited. Setting it on the gradient container does not change the opacity of its child stops.

Confusing stop-opacity With opacity

The stop-opacity property controls individual gradient stops. The opacity property controls the composited appearance of an element or group.

Using Color Keywords

stop {
  stop-opacity: transparent;
}

The keyword transparent is a color value, not an opacity value. Use 0 or 0% for full transparency.

Using Length Values

stop {
  stop-opacity: 10px;
}

Lengths are not valid opacity values.

Expecting Inheritance

The property is not inherited. Set opacity directly on the stops or target multiple stops using CSS selectors.

Forgetting Color Alpha

If stop-color already includes transparency, adding stop-opacity reduces the effective opacity further.

Forgetting the Gradient Reference

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

Using Duplicate Gradient IDs

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

Assuming Transparency Changes the Color

The property changes opacity, not the underlying stop-color value.

Ignoring the Background

Transparent areas reveal underlying content, so the same gradient can appear different over different backgrounds.

Important Considerations

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

  • It controls the opacity of SVG gradient stops.
  • The initial value is 1.
  • The property is not inherited.
  • It applies to SVG <stop> elements.
  • It accepts numbers and percentages.
  • 0 and 0% represent full transparency.
  • 1 and 100% represent full opacity.
  • Values outside the normal range are clamped for rendering.
  • It works with linear and radial SVG gradients.
  • The SVG offset attribute determines stop positions.
  • The browser interpolates opacity between stops.
  • Transparent areas reveal underlying content.
  • It works independently of stop-color.
  • Color alpha and stop opacity are multiplied.
  • It can be declared through CSS or SVG presentation attributes.
  • Ordinary author CSS declarations can override presentation attributes.
  • It can be animated to create fading effects.
  • Gradient definitions must be referenced by an SVG paint property to become visible.
  • Gradient IDs should be unique within the document.
  • Maintain adequate contrast over transparent backgrounds.
  • Respect reduced-motion preferences when animating opacity.
  • Test gradients across supported browsers and display devices.

Browser Support

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

Basic numeric opacity values are broadly supported. Percentage values and CSS calculations should be tested when compatibility with older browsers is required.

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

Feature Detection

@supports (stop-opacity: 0.5) {
  .gradient-end {
    stop-opacity: 0.5;
  }
}

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

Fallback Behavior

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

Testing Recommendations

Test opacity values, percentage syntax, color alpha combinations, animations, and gradient appearance over different backgrounds.

Specifications

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

SVG 2 - stop-opacity Property

The specification defines how gradient stop opacity contributes to the rendering of SVG paint servers.

For additional documentation and examples, consult MDN Web Docs.

MDN Web Docs: stop-opacity