GSAP DrawSVGPlugin (SVG Line Animation)
- Learn how to animate SVG paths as if they are being drawn using GSAP DrawSVGPlugin.
Introduction
DrawSVGPlugin is a GSAP plugin that allows you to animate SVG strokes like they are being drawn by hand.
It is commonly used for:
-
Logo reveal animations
-
Line illustrations
-
Icons and SVG paths
-
Signature-style animations
This plugin is part of GreenSock GSAP’s premium plugins.
-
Basic Concept
SVG paths are drawn using stroke-dasharray and stroke-dashoffset.
👉 DrawSVGPlugin handles all this math for you.
Instead of complex SVG calculations, you simply animate:
drawSVG: "0% 100%"
Include GSAP
DrawSVGPlugin is a Club GreenSock (paid) plugin.
<script src="https://unpkg.com/gsap@3/dist/gsap.min.js"></script>
<script src="https://unpkg.com/gsap@3/dist/DrawSVGPlugin.min.js"></script>
Basic Syntax
gsap.from(".path", {
drawSVG: 0,
duration: 2
});
Parameters / Options
Value Meaning Example 0Nothing visible drawSVG: 0 100%Fully visible drawSVG: "0% 100%" "50% 100%"Half draw Partial draw "100% 0%"Reverse draw Reverse animation
Simple Line Draw
gsap.from("path", {
drawSVG: 0,
duration: 2,
ease: "power2.out"
});
Logo Reveal Animation
gsap.timeline()
.from(".logo-path", {
drawSVG: 0,
duration: 1.5,
stagger: 0.2
});
Reverse Draw Effect
gsap.to(".path", {
drawSVG: "100% 0%",
duration: 2
});
Common Mistakes
-
❌ Using fill instead of stroke
✔ DrawSVG works only with stroke -
❌ Forgetting stroke width
✔ Path must have visible stroke -
❌ Using non-path SVG elements
✔ Works best with<path>,<line>,<polyline> -
❌ Not registering plugin
✔ Usegsap.registerPlugin(DrawSVGPlugin)
-