020

SVG Line Draw on Scroll

£10 or the whole Vault, £99

SVG paths draw themselves as you scroll using the stroke-dasharray technique. Scrubbed or play-once modes, works on any SVG shape, no DrawSVG plugin required.

ScrollTrigger Lenis intermediate
4 more details
svg-line-drawscrubscroll-revealstagger

This demo reads better at your own screen size than in the frame below:

Updated

About this effect

A scroll-driven SVG line drawing effect that animates strokes as if sketched by an invisible pen. It needs no premium plugin: core GSAP plus ScrollTrigger handle everything, and every shape is timed from its own length, so it works on paths, lines, circles, rects and polylines alike. Choose scrubbed drawing that follows the scrollbar in both directions, or a play-once reveal when the artwork enters the viewport.

SVG Line Draw on Scroll - GSAP animation effect preview

What's included

8 items
  • Scrub mode ties drawing progress directly to scroll position, fully reversible
  • Play-once mode draws shapes on viewport entry with configurable duration and ease
  • Auto-measures every shape with getTotalLength(), no manual dash values needed
  • Works on path, line, polyline, polygon, circle, ellipse, and rect elements
  • Length-proportional timing keeps the pen speed consistent across long and short strokes
  • Stagger control for multi-path illustrations, from overlapping cascades to strict sequence
  • No premium plugins required, core GSAP plus ScrollTrigger only
  • Accessible, respects prefers-reduced-motion with fully drawn static artwork

Perfect for

5 use cases
  • Process and roadmap pages where a route draws between milestones as users scroll
  • Hand-drawn signature or logo reveals in hero sections
  • Decorative underline flourishes beneath headings
  • Timeline and journey infographics with branching paths
  • Architectural or technical diagrams that sketch themselves in

How it works

1 section

On load the script finds every drawable shape inside a [data-draw] container and hides its stroke. A timeline then draws each one in: attached to a scrubbed ScrollTrigger the drawing follows the scrollbar exactly, or with scrub disabled it plays once when the container enters the viewport. Each shape takes time in proportion to its own length, so a complex illustration draws at an even, natural pace rather than racing through the long lines.

Plugins ScrollTrigger
Difficulty Intermediate
Smooth scroll Lenis integration
Includes HTML + JS + CSS source, documentation, AI setup prompt, lifetime updates

Lighthouse, as measured

Google Lighthouse on this effect's demo, from the latest scan. A measurement of the demo as shipped, not a promise for your page.

Accessibility
100
Best practices
100

No performance score, on purpose. That figure depends on how you deploy: your server's compression and caching, your CDN, the connection and the device doing the test, none of which the code controls. The same page can score very differently on two consecutive runs, so measure it where it will live.

Paid effect

Purchase to unlock the code.

Buying SVG Line Draw on Scroll opens the HTML, CSS and JavaScript source, the full documentation, an AI setup prompt for your editor, and every update we ship to it. Standard license: unlimited personal and commercial projects. Every paid product is tested for desktop and mobile layouts, reduced-motion handling, animation cleanup and keyboard controls wherever there is something to operate.

£10 Standard license, unlimited projects

Browse free effects

Or the whole library: the Vault, £99, one payment.

Documentation

Quick Start

1. Add to your HTML <head>:

Code snippet omitted: it ships with the download.

2. Add before closing </body> tag:

Code snippet omitted: it ships with the download.

3. Wrap any inline SVG in a data-draw container in your <body>:

Code snippet omitted: it ships with the download.

That is it. The script finds every drawable shape inside the container, measures it with getTotalLength(), and draws it as the container scrolls through the viewport.

Important: shapes must be stroke-based. Set fill="none" and give each shape a stroke and stroke-width (via attributes or CSS).

Modes

Attribute Behavior
data-draw-scrub omitted or "true" Drawing progress is tied to the scrollbar and reverses when scrolling back up
data-draw-scrub="1.2" (any number) Smoothed scrub: drawing catches up to the scrollbar over that many seconds
data-draw-scrub="false" Plays once when the container enters the viewport

Options

All options go on the data-draw container element.

Attribute Values Default Description
data-draw-scrub true, false, number true Scrub with scroll, smoothed scrub, or play once
data-draw-start ScrollTrigger position top 80% When drawing starts (e.g. top 70%)
data-draw-end ScrollTrigger position bottom 60% When drawing completes (scrub mode only)
data-draw-duration Seconds 1.6 Draw time for the longest shape (play-once mode); relative pacing in scrub mode
data-draw-stagger Seconds sequential Delay between successive shape starts. Omit for strict sequence, 0 for all at once
data-draw-ease Any GSAP ease none (scrub), power2.out (play-once) Easing applied to each stroke

Per-shape option:

Attribute Values Description
data-draw-ignore true Placed on a shape or wrapper inside the container to exclude its geometry from line drawing

Supported Elements

Any SVGGeometryElement works because lengths are measured with getTotalLength():

<path>, <line>, <polyline>, <polygon>, <circle>, <ellipse>, <rect>

DOM order is draw order: shapes animate in the order they appear inside the SVG. Geometry nested inside data-draw-ignore="true" or data-draw-reveal is excluded from stroke drawing.

Optional Companion Hooks

These hooks synchronize map labels and atmosphere with the same reversible timeline. They are optional; the core line-draw API is unchanged.

Attribute Placement Description
data-draw-reveal Element inside data-draw Reveals the element with opacity, scale, and vertical movement as the route draws
data-draw-at data-draw-reveal element Normalized reveal position from 0 to 1; evenly distributed when omitted
data-draw-progress Element inside data-draw Outputs an integer from 000 to 100 and updates aria-valuenow
data-draw-atmosphere Element inside data-draw Applies subtle timeline-linked vertical parallax
data-draw-from / data-draw-to Atmosphere element Start and end yPercent; defaults to -1.5 and 1.5

For no-JavaScript safety, leave artwork visible in base CSS. If you pre-hide reveal elements behind a .has-js class, add a reduced-motion rule that makes them fully visible.

Timing Model

  • The longest shape in the container draws over data-draw-duration seconds; every other shape scales proportionally to its measured length, so the pen speed feels constant across the whole illustration.
  • With no data-draw-stagger, shapes draw in strict sequence: each starts when the previous one finishes.
  • With data-draw-stagger="0.2", shape N starts 0.2 x N seconds in, overlapping for an organic cascade. data-draw-stagger="0" draws everything simultaneously.
  • In scrub mode all durations are relative: the whole timeline is mapped onto the scroll distance between data-draw-start and data-draw-end.

Accessibility

  • Reduced motion: respects prefers-reduced-motion. Both the CSS and the JavaScript force stroke-dasharray: none and stroke-dashoffset: 0, so users see the complete artwork immediately with no animation and no blank space
  • Decorative SVGs: mark artwork with aria-hidden="true" and focusable="false" as shown in the examples; if the illustration carries meaning, use role="img" with an aria-label instead
  • No interaction required: the effect is purely scroll-driven, so keyboard and touch users get the identical experience
  • Custom events (linedraw:start, linedraw:complete) allow integration with assistive technologies

Browser Support

Modern browsers (ES6+). getTotalLength() on all geometry elements is supported in all evergreen browsers. Not compatible with IE11.

Dependencies

Required:

  • GSAP 3.12+
  • ScrollTrigger plugin

Optional:

  • Lenis (smooth scroll integration; the script detects it automatically and works without it)

No DrawSVG plugin needed: the effect uses the native stroke-dasharray technique.

Worked examples, the events and programmatic API, and the class reference ship with the download, alongside the full source.