How to Make an SVG Logo Draw Itself With CSS (Step-by-Step)
A complete, copy-paste guide to the "line drawing" logo animation for your website header or page loader. It covers preparing the SVG, the stroke-dash technique, filling in the logo, looping, hover effects and reduced motion.
You have probably seen a logo appear as if an invisible pen were tracing it, with the colours fading in at the end. You don't need After Effects, a video file or a JavaScript library for this. It takes a few lines of CSS on an SVG file you probably already have.
This guide walks through the whole process. The finished file is usually a few kilobytes, stays sharp at any size and can be edited in a text editor.
What you need before you start
- A vector version of your logo (SVG, AI, EPS or PDF). A PNG or JPG won't work. You need the original vector file from your designer.
- A vector editor to clean up the file. Inkscape is free. Illustrator, Affinity Designer and Figma also work.
- A text editor and a browser.
Step 1: Prepare the SVG file
Most export problems happen here, so don't skip it.
- Convert all text to paths. Live text can't be traced. In Illustrator use Type > Create Outlines. In Inkscape use Path > Object to Path. In Figma use Outline Stroke or Flatten.
- Remove hidden layers, guides and empty groups. Each one adds clutter to the code.
- Ungroup and simplify as much as you can, while keeping each letter or shape as its own path.
- Export as plain SVG. In Illustrator, choose "Presentation Attributes" or "Inline Style" for styling. In Inkscape, choose "Plain SVG" or "Optimized SVG" rather than "Inkscape SVG".
- Open the file in a text editor. You should see a `viewBox` attribute and one or more `<path d="...">` elements. If you see `<image>` with a long base64 string, the "vector" file is really a picture inside a wrapper. Go back to the source file.
A key fact: the draw-on effect animates strokes (outlines), not fills. Most logos are filled shapes. That's fine. The standard approach is to trace the outline of each shape and then fade the fill in (Step 4).
Step 2: Add a stroke and give each path a known length
Here is a minimal example: one circle path, ready to animate. Paste it straight into an HTML page:
<svg class="logo" viewBox="0 0 120 120" role="img" aria-labelledby="logo-title"> <title id="logo-title">Your Company</title> <path class="draw" pathLength="1" d="M10 60 a50 50 0 1 0 100 0 a50 50 0 1 0 -100 0" fill="none" stroke="#1a1a1a" stroke-width="4" /> </svg>
The `pathLength="1"` attribute tells the browser to treat the path as 1 unit long, whatever its real length is. That way you don't have to measure each path.
If a browser ever draws the dashes wrongly, measure the real lengths instead. Open the page, open the developer console and run:
document.querySelectorAll('.draw').forEach(p => console.log(p.getTotalLength()))
Then use those numbers in place of `1` in the CSS below. Remove `pathLength`.
Step 3: The draw-on CSS
.draw { stroke-dasharray: 1; stroke-dashoffset: 1; animation: draw 1.6s ease-in-out forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }
How it works: `stroke-dasharray: 1` turns the stroke into one dash as long as the whole path, followed by an equally long gap. `stroke-dashoffset: 1` shifts the pattern so only the gap shows, which means the path starts invisible. Animating the offset to 0 slides the dash into place, and the line looks like it is being drawn. `forwards` keeps the final frame visible after the animation ends.
Fixing a stray dot at the start: with `stroke-linecap="round"` or `"square"`, a small cap can show before the animation begins. Use `stroke-linecap="butt"`, or set both values to `1.01` instead of `1`.
Step 4: Fade in the fill after the line finishes
For a filled logo, use two copies of each shape: an outline that draws and a filled version that fades in. In practice you can often use one path with both properties:
<path class="draw fill-in" pathLength="1" d="..." fill="#e85d2a" stroke="#e85d2a" stroke-width="2" />
.fill-in { fill-opacity: 0; animation: draw 1.6s ease-in-out forwards, fill-in 0.5s ease 1.4s forwards; }
@keyframes fill-in { to { fill-opacity: 1; } }
The fill starts at 1.4s, slightly before the line finishes at 1.6s. That overlap makes the change feel smooth rather than mechanical.
Step 5: Stagger multiple paths (letter by letter)
When a logo has several paths, starting them all at once looks busy. Give each path a number and calculate its delay:
<path class="draw" style="--i:0" pathLength="1" d="..." /> <path class="draw" style="--i:1" pathLength="1" d="..." /> <path class="draw" style="--i:2" pathLength="1" d="..." />
.draw { animation-delay: calc(var(--i) * 0.15s); }
Delays between 0.1s and 0.2s per path usually read as one continuous motion. Longer gaps feel like separate events.
Step 6: Turn it into a looping loader
For a page loader, let it draw and undraw forever:
.loader .draw { stroke-dasharray: 1; stroke-dashoffset: 1; animation: draw 1.8s ease-in-out infinite alternate; }
`alternate` plays the animation forward, then backward, so you avoid an abrupt jump back to empty. Keep loaders simple. One or two paths look better than a full wordmark redrawing on a loop.
Step 7: Add a hover state
A subtle hover effect works well for a header logo that links to your homepage:
.logo .draw { transition: stroke 0.3s ease, transform 0.3s ease; transform-origin: center; transform-box: fill-box; }
.logo:hover .draw { stroke: #e85d2a; transform: scale(1.04); }
Hover only works when the SVG is inline in the page (see Step 9). Touch devices have no real hover, so don't put anything important behind it.
Step 8: Respect reduced-motion settings
Some visitors set their device to reduce motion, for example because of vestibular disorders. Always include this:
@media (prefers-reduced-motion: reduce) { .draw, .fill-in { animation: none; stroke-dashoffset: 0; fill-opacity: 1; } }
Those visitors see the finished logo straight away. To test it, turn on "Reduce motion" in your operating system's accessibility settings and reload the page.
Step 9: Choose how to embed it
How you place the SVG changes what works:
- Inline SVG (the `<svg>` code pasted into your HTML): every feature works, including hover and page CSS. This is the best choice for a header logo.
- `<img src="logo.svg">`: the animation still runs if the CSS is inside the SVG file in a `<style>` block. Your page's stylesheet can't reach inside it, and hover effects on inner paths won't fire. Fine for a simple draw-on.
- CSS background image: same limits as `<img>`.
- Email signatures: many major email clients don't display SVG at all. Use an animated GIF or a static PNG there.
For the `<img>` approach, put the styles inside the SVG file itself:
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 120 120"> <style> .draw { stroke-dasharray: 1; stroke-dashoffset: 1; animation: draw 1.6s ease-in-out forwards; } @keyframes draw { to { stroke-dashoffset: 0; } } @media (prefers-reduced-motion: reduce) { .draw { animation: none; stroke-dashoffset: 0; } } </style> <path class="draw" pathLength="1" d="..." fill="none" stroke="#1a1a1a" stroke-width="4"/> </svg>
(The `xmlns` value is a required namespace identifier, not a link. The browser needs it to read the file as SVG.)
Timing cheat sheet
- Header draw-on: 1.2s to 2s in total. Longer than that makes visitors wait for your navigation.
- Fill fade: 0.3s to 0.6s, starting just before the stroke finishes.
- Loader cycle: 1.5s to 2.5s per direction.
- Hover: 0.2s to 0.3s.
- Easing: `ease-in-out` feels like a hand drawing. `linear` looks robotic on curves.
Pre-launch checklist
- [ ] All text converted to paths; no embedded raster images
- [ ] `viewBox` present; fixed `width`/`height` removed or set by CSS so the logo scales
- [ ] Every animated path has `pathLength="1"` or a measured length
- [ ] No stray dot or flash of the full logo before the animation starts
- [ ] Fill fades in before or as the stroke finishes
- [ ] Reduced-motion rule included and tested
- [ ] `<title>` or `aria-label` set so screen readers announce your company name
- [ ] Tested in Chrome, Firefox and Safari, on desktop and on a phone
- [ ] File size checked (a cleaned logo SVG is usually a few KB; if yours is hundreds of KB, simplify the paths)
- [ ] GIF or PNG fallback ready for email and other places that don't support SVG
Common problems and fixes
- Nothing animates: the path probably has `fill` but no `stroke`. Add a stroke colour and width.
- The line appears all at once: `stroke-dasharray` doesn't match the path length. Check `pathLength` or measure the length.
- Parts draw in a strange direction: each path draws from its starting point. Reverse the path direction in your editor (Inkscape: Path > Reverse; Illustrator: click the start point with the Pen tool, or use the path-direction buttons in the Attributes panel).
- The animation runs once, then never again on navigation: that is normal browser caching behaviour for `<img>` SVGs in some cases. Use inline SVG if it must replay.
- Double outlines on letters: outlined text traces both the inner and outer edges. That often looks good. If it doesn't, have a single centre-line path drawn for the stroke and keep the outlined version for the fill.
Once you've built one, the same structure works for every logo. Only the paths and the timing change.
Browse the Quillwork shop