Text

SVG Line Draw Animation

A stroke that draws itself on, using stroke-dashoffset.

Edit this in the studio

Opens with this animation loaded. Nothing is uploaded — the scene travels in the link.

animation.css
.draw-line {
  transform: translate3d(140px, 60px, 0);
  width: 200px;
  height: 200px;
  background: #00000000;
  stroke-width: 4;
  stroke: #8b7bff;
  stroke-dasharray: 100;
  stroke-dashoffset: 0;
  animation: draw-line-anim 1400ms linear 0ms infinite both;
  will-change: transform, opacity;
}

@keyframes draw-line-anim {
  0% {
    stroke-dashoffset: 100;
    animation-timing-function: ease-in-out;
  }
  100% {
    stroke-dashoffset: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .draw-line {
    animation: none;
    transition: none;
  }
}

Why it is built this way

Setting pathLength="100" on the path normalises its length, so the dash values become percentages and the same CSS works for any shape. Without it you have to measure each path in JavaScript first.

What it animates

1 property across 1 CSS declaration. The bar shows when each one is moving.

Draw
stroke
100 0
2 stopsrepaint

What it costs to run

Stroke repaints on every frame rather than running on the compositor. There is no reflow, so this is far cheaper than animating width or height — but keep the painted area modest.

It runs for 1.40s across 2 keyframe stops, with every property moving over the same window.

One curve throughout: Ease In Out on a path. Keeping a single easing across every property is what makes a multi-property animation read as one movement rather than several things happening at once.

Accessibility

Nothing here hides content — stroke moves over 1.40s and the element is visible throughout. The exported prefers-reduced-motion guard still silences it, which matters most for the looping ones: motion that never stops is the kind that makes people feel unwell.

Related animations

svgstrokedrawline