CSS Portal

CSS stroke-opacity Property

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!

Description

The stroke-opacity property controls the transparency (alpha) applied specifically to an element’s stroke painting. It multiplies the stroke color’s alpha channel so the RGB channels remain unchanged while the stroke becomes more or less transparent. This makes it a precise tool for adjusting how strongly outlines, hairlines, dashed strokes or stroked text appear without altering the stroke hue or the fill.

Because stroke-opacity targets only the stroke, it does not affect fills or other parts of the element unless those parts have their own opacity settings. For example, fill-opacity governs the transparency of the fill separately, while the overall opacity of an element reduces the alpha of the entire element (stroke, fill, children and decorations). The alpha values contributed by color alpha, stroke-opacity and any higher-level opacity are effectively multiplied together to produce the final composited transparency; the stroke color itself comes from the stroke setting.

In practical use, stroke-opacity is handy for subtle visual tuning and for creating smooth reveal/hide effects on strokes via transitions or animations. It works with other stroke-related presentation decisions — for example, you can change whether the stroke is painted above or below the fill using paint-order while independently fading the stroke with stroke-opacity. Because it isolates just the stroke’s alpha, it’s often the simplest way to soften outlines or create layered visual effects without touching colors or global element opacity.

Definition

Initial value
1
Applies to
<circle>, <ellipse>, <line>, <path>, <polygon>, <polyline>, and <rect> elements in an svg
Inherited
yes
Computed value
the specified value, clipped in the range [0,1]
Animatable
by computed value type
JavaScript syntax
object.style.strokeOpacity

Syntax

/* Keyword value */
stroke-opacity: inherit;


/* values */
stroke-opacity: 1; /* Fully opaque */
stroke-opacity: 0.5; /* 50% transparent */
stroke-opacity: 0; /* Fully transparent */


/* values */
stroke-opacity: 100%;
stroke-opacity: 25%;

Values

  • <number>A value between 0.0 and 1.0. 0 is completely transparent, and 1 is completely opaque.
  • <percentage>A value between 0% and 100%. This maps directly to the 0.0–1.0 range (e.g., 50% is 0.5).
  • inheritThe element takes the stroke-opacity value from its parent element.

Example

<svg width="250" height="100">
<rect x="10" y="10" width="50" height="50" class="stroke-full"/>
<rect x="90" y="10" width="50" height="50" class="stroke-half"/>
<rect x="170" y="10" width="50" height="50" class="stroke-none"/>
</svg>
.stroke-full {
    stroke: red;
    stroke-width: 5;
    stroke-opacity: 1; /* fully visible */
    fill: none;
}

/* Semi-transparent stroke */
.stroke-half {
    stroke: blue;
    stroke-width: 5;
    stroke-opacity: 0.5; /* 50% transparent */
    fill: none;
}

/* Invisible stroke */
.stroke-none {
    stroke: green;
    stroke-width: 5;
    stroke-opacity: 0; /* fully transparent */
    fill: none;
}

Browser Support

The following information will show you the current browser support for the CSS stroke-opacity property. Hover over a browser icon to see the version that first introduced support for this CSS property.

This property is supported by all modern browsers.
Desktop
Chrome
Edge
Firefox
Opera
Safari
Tablets & Mobile
Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-

Last updated by CSSPortal on: 28th December 2025

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!