Thanks to visit codestin.com
Credit goes to www.cssportal.com

CSS Portal

CSS stroke-dashoffset 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-dashoffset property controls where along a shape's outline the dash pattern begins by shifting the dash pattern forward or backward along the path. In effect it does not change the dashes themselves but repositions the entire sequence of dashes and gaps relative to the path's starting point, so the visible pattern appears to slide along the stroke. The offset operates in the path's coordinate space and follows the path's direction: changing the path direction (for example by reversing the point order) changes which way positive offsets move the pattern.

This property is most often used together with a dash pattern set by stroke-dasharray. While the dash array defines the lengths of dashes and gaps, stroke-dashoffset determines the initial phase of that repeating pattern. Visual details such as how each dash terminates and how gaps look are influenced by stroke-related properties like stroke-linecap, the stroke thickness from stroke-width, and the stroke color specified by stroke. Because the offset simply translates the pattern along the path, changes to those other properties affect the final rendered appearance but not the relative shift the offset produces.

A common practical use is creating "draw-on" or sliding-dash animations: by combining stroke-dashoffset animation with an appropriate dash pattern you can make a path appear to be progressively drawn or to have dashes march along it. For example, designers often set a dash pattern that equals the path length and then animate the offset so the path appears to reveal itself. When animating, be aware the offset is measured in the path's units and can produce subpixel results; you can also control whether a stroke scales with transforms (which affects perceived offset) using effects like vector-effect.

Behavior across complex shapes: within a single SVG path element the dash pattern and offset continue across subpaths—so the pattern does not automatically restart at each move command—whereas separate path elements are independent. Because stroke-dashoffset is relative to the path geometry and its start point, small changes to the path coordinates, element order, or transforms can produce noticeably different visual alignments. For best results, plan the path direction and use consistent units and transforms so the offset produces the expected visual rhythm.

Definition

Initial value
0
Applies to
inline boxes and SVG shapes
Inherited
Yes
Computed value
an absolute <length> or <percentage>, numbers converted to absolute lengths first
Animatable
as repeated list of integers
JavaScript syntax
object.style.strokeDashoffset

Syntax

stroke-dashoffset = <length-percentage>

Values

  • <length-percentage>A numeric length that shifts the dash pattern along the stroke. Can be positive or negative. Measured in user units (the same units used to draw the SVG, usually pixels)

Example

<div class="container">
<svg class="ring" width="200" height="200" viewBox="0 0 120 120" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
<circle class="ring__bg" cx="60" cy="60" r="54" fill="none" stroke="#eee" stroke-width="12" />
<circle class="ring__dash" cx="60" cy="60" r="54" fill="none" stroke="#ff6b6b" stroke-width="12" stroke-linecap="round" />
</svg>
<div class="label">stroke-dashoffset animation</div>
</div>
.container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial;
  padding: 20px;
  color: #333;
}

.ring {
  width: 160px;
  height: 160px;
  transform: rotate(-90deg); /* start the stroke at 12 o'clock */
}

.ring__bg {
  /* background track */
}

.ring__dash {
  /* Circumference = 2 * π * r = 2 * π * 54 ≈ 339.292 */
  stroke-dasharray: 339.292;
  stroke-dashoffset: 339.292; /* fully hidden */
  transition: stroke-dashoffset 0.8s ease;
  animation: draw 3s ease-in-out infinite alternate;
}

@keyframes draw {
  0% {
    stroke-dashoffset: 339.292; /* 0% visible */
  }
  100% {
    stroke-dashoffset: 84.823; /* 75% of circle visible (offset = 25% of circumference) */
  }
}

.label {
  font-size: 14px;
}

Browser Support

The following information will show you the current browser support for the CSS stroke-dashoffset 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: 1st January 2026

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