# Path Draw

> Any SVG drawn with strokes draws itself stroke by stroke at a steady pen speed, then fills in. Once on entering the screen, or tied to the scroll.

SVG & Drawing · svg, line drawing, signature, logo, illustration, stroke, draw on scroll, handwriting · HTML, CSS, vanilla JS · no dependencies · updated 2026-11-04
Demo: https://kodza.dev/components/path-draw/
Source on GitHub: https://github.com/kodza-dev/kodza/tree/main/components/path-draw

Takes the whole screen (or reacts to the page scroll): give it a page, not a small box.

## Files

The code below, served as files: byte for byte what the Kodza site copies (the CSS includes its theme guard).

- [`kodza-path-draw.css`](https://kodza.dev/registry/path-draw/kodza-path-draw.css) · 3.0 KB
- [`kodza-path-draw.js`](https://kodza.dev/registry/path-draw/kodza-path-draw.js) · 12.9 KB
- [`kodza-path-draw.html`](https://kodza.dev/registry/path-draw/kodza-path-draw.html) · 2.9 KB · the markup, to adapt and paste into your page

**Can you run shell commands? Download the CSS and the JS, don't retype them.** Retyping costs thousands of tokens and can drop or change lines of the CSS. Put the files where your stack expects them (Use it says where: change the `-o` paths):

```bash
curl -fsSL --create-dirs -o kodza/kodza-path-draw.css https://kodza.dev/registry/path-draw/kodza-path-draw.css
curl -fsSL --create-dirs -o kodza/kodza-path-draw.js https://kodza.dev/registry/path-draw/kodza-path-draw.js
```

Then load the files from your page as Use it shows, instead of pasting the content. The HTML is the part you adapt (text, links, modifiers): paste it from the Code section. Copy the CSS and the JS from the Code section only if you can't run commands, exactly as they are. (Windows PowerShell: `curl.exe`.)

## API

- Root: `.kodza-path-draw`
- Variables (set them on the root element itself: it declares its own defaults):
  - `--kz-path-draw-ink: #0a0a0a` — the colour of a drawing in currentColor
  - `--kz-path-draw-width: auto` — the drawing's width (auto: the width written on the svg)
  - `--kz-path-draw-fill-time: 0.7s` — the fills coming in once the last stroke is down
- Attributes:
  - `data-draw`
- Lifecycle: `kodza:init` / `kodza:destroy` on `document`, with `{ detail: { root } }` to target a container.

## Dark mode

The values Kodza uses on a dark background (`#0a0a0a`). For a page that follows the system theme, add them after the component's CSS:

```css
@media (prefers-color-scheme: dark) {
  .kodza-path-draw {
    --kz-path-draw-ink: #f2f2f0;
  }
}
```

A site with its own theme switch puts the same rules under its dark selector instead (`[data-theme="dark"] .kodza-path-draw { … }`); a single dark section, under that section's class.

## Use it

### Plain HTML page

- CSS: `kodza/kodza-path-draw.css` next to the page (the Files commands as they are), linked in `<head>`: `<link rel="stylesheet" href="kodza/kodza-path-draw.css">`. Without a shell, paste it in a `<style>` in `<head>` instead. It only touches `kodza-` classes.
- HTML: where the component goes. Paste it as many times as you need: instances never interfere.
- JS: `kodza/kodza-path-draw.js`, loaded with `<script src="kodza/kodza-path-draw.js" defer></script>` in `<head>`. Without a shell, paste it in a `<script>` before `</body>` (or in `<head>`: it waits for the page). One copy per page, whatever the number of instances.
- Restyle with the `--kz-…` variables, set on the component's root element itself (the root declares its own defaults, so a value on an ancestor is ignored), and with the modifiers / attributes listed under API.
- Font: it takes the page's own. The Kodza look is Geist: `<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Geist:wght@400;500;600;700&family=Geist+Mono:wght@400;500&display=swap">`.
- Motion: a site sets its pace once for every Kodza component, on `:root`, never by editing the CSS or the JS: `--kz-motion-scale` multiplies every duration (`0.5` twice as fast, `2` twice as slow, `0` no motion at all, loops stopped, like reduced motion). Unset, nothing changes.
- Content added later (AJAX navigation, a SPA route, a builder preview): start it with `document.dispatchEvent(new CustomEvent('kodza:init', { detail: { root: container } }))`; before removing it, the same call with `'kodza:destroy'` stops it and puts the original markup back.

### Claude artifact (claude.ai)

- Paste the CSS in a `<style>` and the JS in a `<script>` at the end, in the artifact itself: it loads stylesheets only from Google Fonts and scripts only from a few CDNs, so no `<link>` or `<script src>` to Kodza.
- Writing the artifact file with a shell? Insert the downloaded files (Files) with a command instead of retyping them: a line `KODZA-CSS` alone inside the `<style>`, `KODZA-JS` inside the `<script>`, then `sed -e '/^KODZA-CSS$/{r kodza/kodza-path-draw.css' -e 'd' -e '}' -e '/^KODZA-JS$/{r kodza/kodza-path-draw.js' -e 'd' -e '}' page.html > artifact.html`.
- Font: load Geist from Google Fonts (allowed): `<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Geist:wght@400;500;600;700&family=Geist+Mono:wght@400;500&display=swap">`.
- Motion: a site sets its pace once for every Kodza component, on `:root`, never by editing the CSS or the JS: `--kz-motion-scale` multiplies every duration (`0.5` twice as fast, `2` twice as slow, `0` no motion at all, loops stopped, like reduced motion). Unset, nothing changes.
- Dark mode: the viewer sets `data-theme="dark"` or `"light"` on `<html>`, or nothing when it follows the system. Write the Dark mode rules twice: inside `@media (prefers-color-scheme: dark)` with `:root:not([data-theme="light"])` in front of each selector, and with `:root[data-theme="dark"]` in front of each selector.

### WordPress

- HTML: a **Custom HTML** block (or a pattern / template part). WordPress keeps this markup as it is only for users allowed to post unfiltered HTML (Administrators; Super Admins on multisite): for anyone else it strips tags such as `<svg>`, `<input>` or `<dialog>`, so add it from the theme (a pattern or template part) instead.
- This one spans the page: a block theme keeps a Custom HTML block to the width of the text column, so put it inside a **Group** block set to **Full width**, with **Inner blocks use content width** turned off.
- CSS and JS: the downloaded files go in the theme, under `wp-content/themes/<your-theme>/kodza/` (the child theme if there is one), enqueued from its functions.php (or a code-snippets plugin):
  ```php
  add_action('wp_enqueue_scripts', function () {
    $dir = get_stylesheet_directory() . '/kodza/';
    $uri = get_stylesheet_directory_uri() . '/kodza/';
    wp_enqueue_style('kodza-path-draw', $uri . 'kodza-path-draw.css', [], filemtime($dir . 'kodza-path-draw.css'));
    wp_enqueue_script('kodza-path-draw', $uri . 'kodza-path-draw.js', [], filemtime($dir . 'kodza-path-draw.js'), true);
  });
  ```
  Scoped to `kodza-` classes, the CSS never touches the theme. One copy of the JS, whatever the number of blocks.
- No access to the theme files? The CSS can also go, as it is, in **Appearance → Customize → Additional CSS** (classic theme) or **Styles → Additional CSS** in the Site Editor (block theme).
- Theme with AJAX page transitions: fire `kodza:init` on the new content after each swap (and `kodza:destroy` on the old one).
- Performance plugin (WP Rocket, LiteSpeed Cache, Perfmatters…) with **Delay JavaScript execution** turned on: add `kodza` to the scripts it must not delay. Otherwise the component waits for the visitor's first scroll, tap or mouse move, and that first click can be lost.
- Colours: it takes the colour of the text around it (or keeps its own monochrome): nothing to point at the theme.
- WordPress turns straight quotes and `--` into typographic ones in the text of a Custom HTML block (not inside `<code>` or `<pre>`).

#### With Elementor

- HTML: an **HTML** widget (Elementor shows it to administrators only). It keeps the code exactly as pasted, straight quotes included.
- This one spans the page: give the widget its own container, **Content Width: Full Width**, padding 0.
- CSS and JS: as above. Elementor's Site Settings → Theme Style styles every button, field, link and image of the page, components included; the theme guard at the end of the CSS keeps the component's buttons, fields and link colours as they are.
- The Elementor editor redraws each widget after the page has loaded: without the script below, the component stays still in the editor preview (the published page works). Add it once per site, in the footer like the component's script (`kodza/elementor-editor.js`, or a code-snippets plugin):

```js
// Kodza in the Elementor editor: the editor redraws each HTML widget after the page has loaded.
// Start Kodza in what it draws, stop it in what it replaces or removes. Once per site.
window.addEventListener('elementor/frontend/init', () => {
  if (!elementorFrontend.isEditMode()) return;
  class KodzaWidget extends elementorModules.frontend.handlers.Base {
    onInit() {
      super.onInit();
      this.kodza = [...this.$element[0].children];
      document.dispatchEvent(new CustomEvent('kodza:init', { detail: { root: this.$element[0] } }));
    }
    onDestroy() {
      super.onDestroy();
      this.kodza.forEach((root) => document.dispatchEvent(new CustomEvent('kodza:destroy', { detail: { root } })));
    }
  }
  elementorFrontend.elementsHandler.attachHandler('html', KodzaWidget);
});
```

- No child theme: everything can go in the HTML widget instead, `<style>` with the CSS, the HTML, then `<script>` with the JS. It works on the page and in the editor without the script above.

### Shopify

- Files: `assets/kodza-path-draw.css` and `assets/kodza-path-draw.js` (the Files commands with `-o assets/…`).
- In the section: `{{ 'kodza-path-draw.css' | asset_url | stylesheet_tag }}` and `<script src="{{ 'kodza-path-draw.js' | asset_url }}" defer></script>`, then the HTML.
- The theme editor re-renders sections: restart them with
  `document.addEventListener('shopify:section:load', (e) => document.dispatchEvent(new CustomEvent('kodza:init', { detail: { root: e.target } })));`
  and the same with `shopify:section:unload` → `kodza:destroy`.

### React / Next.js

- Files, side by side (e.g. in `components/kodza/`): `PathDraw.tsx` (below), the CSS block under Code saved as `path-draw.css` and the JS block as `path-draw.js`, both as they are. The HTML block is already inside the component: skip it.
- Use it: `import { PathDraw } from '@/components/kodza/PathDraw';` then `<PathDraw />`. Props: `vars` (the `--kz-…` variables listed under API, e.g. `vars={{ '--kz-path-draw-ink': … }}`), `className`, `style` and the other props of its `<div>` (`onClick`, `aria-…`).
- Next.js App Router: it is a Client Component already (`'use client'`). Pages Router: Next.js takes global CSS only in `pages/_app`, so move the `import './path-draw.css'` line there.
- Safe under StrictMode, client-side navigation and prop changes: when a prop changes, the `key` gives React a fresh element, `kodza:destroy` stops the script on the old one and `kodza:init` starts it on the new one.
- Built from your data (tabs, rows, options)? Add what the markup is made of to the `key`, as plain values (ids, text, numbers). What the visitor changes (the open tab, the sort, what they type) is the script's: follow it with `onClick` or `onInput` on the root, and change it from your code as a visitor would (click the tab; set the field's value, then dispatch a bubbling `input` event). Fields stay uncontrolled (`defaultValue`, `name`).

```tsx
'use client';
// Kodza — Path Draw, for React. From https://kodza.dev/components/path-draw/
// Kodza License: free to use, client work included. Not to resell or redistribute, ported or not: https://kodza.dev/docs/#print-license
// Next to this file: path-draw.css and path-draw.js, the component's CSS and JS from Kodza, as they are.
// Yours to edit: the markup is plain JSX below.
// The script changes this markup once React has rendered it (it adds layers, splits text, moves
// nodes), so React must not patch it afterwards. When a prop changes, the key gives React a fresh
// element: kodza:destroy stops the script on the old one, kodza:init starts it on the new one.
// data-kodza-manual keeps the script from starting it on its own: the effect below does, once
// React has hydrated the markup (on a page that streams in, the script can load first).
// Built from your data (tabs, rows, options)? Put what the markup is made of in the key, as plain
// values (ids, text, numbers): a change starts the script again on fresh markup. What the visitor
// changes (the open tab, the sort, what they type) is the script's: keep it out of the key, follow
// it with onClick or onInput on the root, and change it from your code as a visitor would (click
// the tab; set the field's value, then dispatch a bubbling input event).
import { useRef, useEffect, type ComponentPropsWithoutRef, type ComponentRef, type CSSProperties } from 'react';
import './path-draw.css';

export type PathDrawProps = Omit<ComponentPropsWithoutRef<'div'>, "children" | "vars"> & {
  /** Settings, as CSS variables on the root */
  vars?: {
    /** the colour of a drawing in currentColor — default: #0a0a0a */
    "--kz-path-draw-ink"?: string | number;
    /** the drawing's width (auto: the width written on the svg) — default: auto */
    "--kz-path-draw-width"?: string | number;
    /** the fills coming in once the last stroke is down — default: 0.7s */
    "--kz-path-draw-fill-time"?: string | number;
  };
  className?: string;
};

export function PathDraw({ vars, className, style, ...rest }: PathDrawProps) {
  const ref = useRef<ComponentRef<'div'>>(null);
  const classes = ["kodza-path-draw", className].filter(Boolean).join(' ');
  // Everything the markup is made of: when it changes, React gets a fresh element (see the top)
  const key = JSON.stringify([classes, vars, style, rest]);

  // Starts the script on this element once React has rendered it, stops it when it goes
  useEffect(() => {
    const root = ref.current;
    let live = true;
    // @ts-ignore: a plain script, no types to find
    import('./path-draw.js').then(() => {
      if (live) document.dispatchEvent(new CustomEvent('kodza:init', { detail: { root } }));
    });
    return () => {
      live = false;
      document.dispatchEvent(new CustomEvent('kodza:destroy', { detail: { root } }));
    };
  }, [key]);

  return (
    <div key={key} {...rest} className={classes} data-kodza-manual style={{ ...vars, ...style } as CSSProperties} ref={ref}>
      <svg viewBox="0 0 226 154" width="226" height="154" fill="none" stroke="currentColor" strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round" role="img" aria-label="Signature">
        <path d="M24.9,44 C28.3,40.3 37.5,28 45.2,22 C53,16 65.4,9.7 71.2,8 C77.1,6.3 80.4,7.3 80.1,12 C79.8,16.7 74.7,25 69.2,36 C63.7,47 53.7,65.7 47.2,78 C40.6,90.3 35.4,101.7 30,110 C24.6,118.3 18.8,125.3 14.8,128 C10.9,130.7 6.4,128.3 6.4,126 C6.4,123.7 9.6,117.7 14.9,114 C20.1,110.3 31.7,105.3 37.7,104 C43.8,102.7 46.9,105.6 51.1,106 C55.4,106.4 59.8,107.9 63.1,106.5 C66.4,105.1 69.1,100.8 71.1,97.6 C73.1,94.4 74.6,90.3 75.2,87.5 C75.9,84.7 75.5,82 74.8,80.9 C74,79.8 72.3,79.8 70.9,80.9 C69.6,82 67.6,84.7 66.7,87.5 C65.7,90.3 64.8,94.4 65,97.6 C65.2,100.8 66.2,104.4 67.9,106.5 C69.6,108.6 71.5,110.9 75,110 C78.5,109.1 84.4,106.4 88.9,101.3 C93.5,96.2 98.9,87.2 102.4,79.4 C106,71.6 109.1,61.4 110.4,54.5 C111.7,47.6 111.4,40.9 110.1,38.2 C108.9,35.5 105.8,35.5 103,38.2 C100.2,40.9 96.1,47.6 93.5,54.5 C90.8,61.4 88,71.6 87.1,79.4 C86.2,87.2 86.4,96.2 88,101.3 C89.7,106.4 94.7,109.1 97,110 C99.3,110.9 100.2,108.7 102,106.8 C103.8,105 105.9,101.7 107.7,98.8 C109.5,96 111.4,92.3 112.9,89.8 C114.3,87.2 115.5,84.8 116.3,83.8 C117.1,82.8 117.5,82.8 117.7,83.8 C118,84.8 117.7,87.2 117.7,89.8 C117.7,92.3 117.5,96 117.7,98.8 C117.9,101.7 118.1,105 118.8,106.8 C119.6,108.7 120.1,110 122,110 C123.9,110 127.7,108.8 130.2,107.1 C132.8,105.4 135.5,102.3 137.3,99.7 C139.1,97 140.4,93.6 141,91.2 C141.5,88.9 141.2,86.7 140.6,85.8 C140,84.8 138.5,84.8 137.3,85.8 C136.2,86.7 134.6,88.9 133.8,91.2 C133,93.6 132.4,97 132.6,99.7 C132.9,102.3 133.9,105.4 135.5,107.1 C137,108.8 138.9,110.7 142,110 C145.1,109.3 150.1,107.1 153.9,103 C157.8,98.8 162.4,91.5 165.4,85.2 C168.4,78.9 170.9,70.6 172,65 C173,59.4 172.7,54 171.7,51.8 C170.6,49.6 168,49.6 165.7,51.8 C163.4,54 160,59.4 157.8,65 C155.7,70.6 153.5,78.9 152.8,85.2 C152.2,91.5 152.6,98.8 154.1,103 C155.6,107.1 159.5,109.3 162,110 C164.5,110.7 167.1,108.9 169.3,107.4 C171.6,105.9 174.1,103.2 175.7,100.9 C177.4,98.6 178.6,95.5 179.1,93.5 C179.7,91.5 179.4,89.5 179,88.7 C178.5,87.9 177.2,87.9 176.3,88.7 C175.3,89.5 174,91.5 173.3,93.5 C172.7,95.5 172.2,98.6 172.5,100.9 C172.8,103.2 173.7,105.9 175.1,107.4 C176.5,108.9 179.2,110 181,110 C182.8,110 184.3,109 186,107.7 C187.7,106.3 189.7,103.8 191.2,101.7 C192.7,99.6 194.2,96.9 195.2,95 C196.3,93.1 196.9,91.3 197.4,90.6 C197.8,89.9 197.8,89.9 197.8,90.6 C197.8,91.3 197.4,93.1 197.4,95 C197.3,96.9 197.2,99.6 197.5,101.7 C197.8,103.8 196.6,105.6 199.3,107.7 C202,109.7 211.1,110.6 213.9,114 C216.6,117.4 218.5,123.3 215.8,128 C213.2,132.7 210.1,138.7 197.8,142 C185.5,145.3 164.5,147.7 142.1,148 C119.7,148.3 85.8,146.7 63.3,144 C40.7,141.3 16.1,134 6.7,132" />
        <path d="M144.6,66 C147.7,65.7 156.9,65 163.2,64 C169.5,63 179.1,60.7 182.3,60" />
        <path d="M124,68 C124.5,67.8 126.5,66.8 127,66.5" />
      </svg>
    </div>
  );
}
```

## Code

```html
<div class="kodza-path-draw">
  <svg viewBox="0 0 226 154" width="226" height="154" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" role="img" aria-label="Signature">
    <path d="M24.9,44 C28.3,40.3 37.5,28 45.2,22 C53,16 65.4,9.7 71.2,8 C77.1,6.3 80.4,7.3 80.1,12 C79.8,16.7 74.7,25 69.2,36 C63.7,47 53.7,65.7 47.2,78 C40.6,90.3 35.4,101.7 30,110 C24.6,118.3 18.8,125.3 14.8,128 C10.9,130.7 6.4,128.3 6.4,126 C6.4,123.7 9.6,117.7 14.9,114 C20.1,110.3 31.7,105.3 37.7,104 C43.8,102.7 46.9,105.6 51.1,106 C55.4,106.4 59.8,107.9 63.1,106.5 C66.4,105.1 69.1,100.8 71.1,97.6 C73.1,94.4 74.6,90.3 75.2,87.5 C75.9,84.7 75.5,82 74.8,80.9 C74,79.8 72.3,79.8 70.9,80.9 C69.6,82 67.6,84.7 66.7,87.5 C65.7,90.3 64.8,94.4 65,97.6 C65.2,100.8 66.2,104.4 67.9,106.5 C69.6,108.6 71.5,110.9 75,110 C78.5,109.1 84.4,106.4 88.9,101.3 C93.5,96.2 98.9,87.2 102.4,79.4 C106,71.6 109.1,61.4 110.4,54.5 C111.7,47.6 111.4,40.9 110.1,38.2 C108.9,35.5 105.8,35.5 103,38.2 C100.2,40.9 96.1,47.6 93.5,54.5 C90.8,61.4 88,71.6 87.1,79.4 C86.2,87.2 86.4,96.2 88,101.3 C89.7,106.4 94.7,109.1 97,110 C99.3,110.9 100.2,108.7 102,106.8 C103.8,105 105.9,101.7 107.7,98.8 C109.5,96 111.4,92.3 112.9,89.8 C114.3,87.2 115.5,84.8 116.3,83.8 C117.1,82.8 117.5,82.8 117.7,83.8 C118,84.8 117.7,87.2 117.7,89.8 C117.7,92.3 117.5,96 117.7,98.8 C117.9,101.7 118.1,105 118.8,106.8 C119.6,108.7 120.1,110 122,110 C123.9,110 127.7,108.8 130.2,107.1 C132.8,105.4 135.5,102.3 137.3,99.7 C139.1,97 140.4,93.6 141,91.2 C141.5,88.9 141.2,86.7 140.6,85.8 C140,84.8 138.5,84.8 137.3,85.8 C136.2,86.7 134.6,88.9 133.8,91.2 C133,93.6 132.4,97 132.6,99.7 C132.9,102.3 133.9,105.4 135.5,107.1 C137,108.8 138.9,110.7 142,110 C145.1,109.3 150.1,107.1 153.9,103 C157.8,98.8 162.4,91.5 165.4,85.2 C168.4,78.9 170.9,70.6 172,65 C173,59.4 172.7,54 171.7,51.8 C170.6,49.6 168,49.6 165.7,51.8 C163.4,54 160,59.4 157.8,65 C155.7,70.6 153.5,78.9 152.8,85.2 C152.2,91.5 152.6,98.8 154.1,103 C155.6,107.1 159.5,109.3 162,110 C164.5,110.7 167.1,108.9 169.3,107.4 C171.6,105.9 174.1,103.2 175.7,100.9 C177.4,98.6 178.6,95.5 179.1,93.5 C179.7,91.5 179.4,89.5 179,88.7 C178.5,87.9 177.2,87.9 176.3,88.7 C175.3,89.5 174,91.5 173.3,93.5 C172.7,95.5 172.2,98.6 172.5,100.9 C172.8,103.2 173.7,105.9 175.1,107.4 C176.5,108.9 179.2,110 181,110 C182.8,110 184.3,109 186,107.7 C187.7,106.3 189.7,103.8 191.2,101.7 C192.7,99.6 194.2,96.9 195.2,95 C196.3,93.1 196.9,91.3 197.4,90.6 C197.8,89.9 197.8,89.9 197.8,90.6 C197.8,91.3 197.4,93.1 197.4,95 C197.3,96.9 197.2,99.6 197.5,101.7 C197.8,103.8 196.6,105.6 199.3,107.7 C202,109.7 211.1,110.6 213.9,114 C216.6,117.4 218.5,123.3 215.8,128 C213.2,132.7 210.1,138.7 197.8,142 C185.5,145.3 164.5,147.7 142.1,148 C119.7,148.3 85.8,146.7 63.3,144 C40.7,141.3 16.1,134 6.7,132"/>
    <path d="M144.6,66 C147.7,65.7 156.9,65 163.2,64 C169.5,63 179.1,60.7 182.3,60"/>
    <path d="M124,68 C124.5,67.8 126.5,66.8 127,66.5"/>
  </svg>
</div>
```

```css
/* Kodza License: free to use, client work included. Not to resell or redistribute, ported or not: https://kodza.dev/docs/#print-license */
/* Kodza — Path Draw
   Any SVG drawn with strokes, put inside, draws itself stroke by stroke: in the order of the
   markup, at the steady speed of a pen (a long stroke takes longer than a short one), lifting
   the pen between two strokes, then its fills come in. Without the script, the drawing is simply
   there. The colour and the fills are tuned with the --kz-path-draw-* variables, the pen with
   the constants at the top of component.js, the trigger with data-draw. */
.kodza-path-draw {
  --kz-path-draw-ink: #0a0a0a; /* the colour of a drawing in currentColor */
  --kz-path-draw-width: auto; /* the drawing's width (auto: the width written on the svg) */
  --kz-path-draw-fill-time: 0.7s; /* the fills coming in once the last stroke is down */

  display: block;
  color: var(--kz-path-draw-ink);
}

.kodza-path-draw svg {
  display: block;
  width: var(--kz-path-draw-width);
  max-width: 100%;
  height: auto;
  overflow: visible; /* round caps at the edge of the viewBox are not cut */
}

/* The fills wait for the last stroke (only once the script is there) */
.kodza-path-draw.is-ready svg * {
  transition: fill-opacity calc(var(--kz-path-draw-fill-time) * var(--kz-motion-scale, 1)) ease;
}

.kodza-path-draw.is-ready:not(.is-filled) svg * {
  fill-opacity: 0;
}

@media (prefers-reduced-motion: reduce) {
  .kodza-path-draw.is-ready svg * {
    transition-duration: 0.01ms !important;
  }
}

/* kodza-guard 0cd8cdf6fcbe — generated by Kodza, do not edit.
   Theme guard: keeps a site's own CSS (WordPress themes, Bootstrap, CSS resets…) off this
   component. :not(#_) is always true and weighs as much as an id, so these lines win over
   theme rules made of classes and tags. Customise the component through its --kz-* variables. */

/* What the browser gives, on everything the component leaves to it */

.kodza-path-draw:not(#_) {
  box-sizing: revert;
}

.kodza-path-draw svg:where(:not([class*="kodza-"])):not(#_) {
  border: revert;
  margin: revert;
  padding: revert;
  border-radius: revert;
  outline: revert;
  text-decoration: revert;
  transition: revert;
  list-style: revert;
  box-sizing: revert;
  float: revert;
  position: revert;
  background-color: revert;
  background-image: revert;
  box-shadow: revert;
  outline-offset: revert;
  appearance: revert;
  max-height: revert;
  color: revert;
  font-family: revert;
  font-size: revert;
  font-weight: revert;
  font-style: revert;
  line-height: revert;
  letter-spacing: revert;
  text-transform: revert;
  text-underline-offset: revert;
  text-align: revert;
  text-indent: revert;
  text-shadow: revert;
  vertical-align: revert;
}

/* The component's own rules, one step stronger: real buttons and fields, what it sets on tags themes style (links, lists, headings, images…), and the root width (a theme may narrow it, never widen it) */

.kodza-path-draw svg:not(#_) {
  display: block;
  max-width: 100%;
}
```

```js
// Kodza License: free to use, client work included. Not to resell or redistribute, ported or not: https://kodza.dev/docs/#print-license
// Kodza — Path Draw
// Any SVG drawn with strokes, put inside, draws itself as if someone drew it in front of you:
// stroke by stroke in the order of the markup, at a pen's steady speed (a stroke lasts as long
// as it is long on screen), lifting the pen between two strokes, then its fills come in. On
// entering the screen, once (the default), or tied to the scroll with data-draw="scroll" (it
// undraws when you scroll back). `kodza:replay` on the root draws it again. The figures you can
// tune are the constants below; the colour and the fills are in the CSS.
(() => {
  const SELECTOR = '.kodza-path-draw';
  const SPEED = 520; // px of stroke a second, on screen
  const RAMP = 160; // ms the pen takes to reach that speed, and to stop at the end of a stroke
  const LIFT = 160; // ms the pen is lifted between two strokes
  const START = 0.9; // tied to the scroll: nothing is drawn while its top is below this share of the screen…
  const END = 0.45; // …and everything once its middle is above this one
  const GLIDE = 0.14; // tied to the scroll: how much of the way the pen catches up each frame
  const FOLLOW = 3; // tied to the scroll: how much faster than SPEED the pen may catch up
  const SHAPES = 'path, line, polyline, polygon, circle, ellipse, rect'; // what draws, when it has a stroke
  const BORROWED = 'defs, clipPath, mask, symbol, marker, pattern'; // shapes inside these are not drawn
  const reduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
  // The site's pace, --kz-motion-scale (set on :root, read on the instance): every duration of the
  // script times it, and 0 moves nothing, like reduced motion
  const paceOf = (el) => {
    const pace = parseFloat(getComputedStyle(el).getPropertyValue('--kz-motion-scale'));
    return pace >= 0 ? pace : 1;
  };
  // How far a hand is along a stroke `time` ms long, `t` ms in (0 to 1): it picks up speed over
  // `ramp` ms, runs at a steady speed, and slows down over the last `ramp` ms
  const hand = (t, time, ramp) => {
    const r = Math.min(ramp, time / 2);
    const run = time - r; // the length, in ms at full speed
    if (t <= 0) return 0;
    if (t >= time) return 1;
    if (t < r) return (t * t) / (2 * r) / run;
    if (t <= time - r) return (t - r / 2) / run;
    return 1 - (time - t) ** 2 / (2 * r) / run;
  };

  // One instance. Everything it starts is tied to `signal`, so kodza:destroy stops it all
  function mount(root, signal) {
    const pace = paceOf(root);
    // The still path: drawn and filled at once. The pace slows the pen (2 = half the speed)
    const still = reduceMotion || !pace;
    const scrolled = root.dataset.draw === 'scroll';
    const strokes = [...root.querySelectorAll(SHAPES)]
      .filter((el) => !el.closest(BORROWED) && getComputedStyle(el).stroke !== 'none')
      .map((el) => ({ el, units: parseFloat(el.getAttribute('pathLength')) || el.getTotalLength() }));
    const fill = (on) => root.classList.toggle('is-filled', on);
    if (still || !strokes.length) {
      fill(true);
      return;
    }

    // The timeline, in ms: each stroke lasts its length on screen at SPEED, a lift between two
    let total = 0;
    const time = () => {
      total = 0;
      strokes.forEach((stroke, i) => {
        const m = stroke.el.getCTM(); // the stroke's scale, inside the svg (viewBox and transforms)
        const px = stroke.el.getTotalLength() * (m ? Math.hypot(m.a, m.b) : 1);
        stroke.start = total + (i ? LIFT * pace : 0);
        stroke.time = Math.max((px / SPEED) * 1000 * pace, 1) + RAMP * pace; // the ramps on top of the run
        total = stroke.start + stroke.time;
      });
    };

    // The drawing at `t` ms of its timeline: the strokes before it down (their own dashes back),
    // the one under the pen inked by its length, the next ones not started, the fills at the end
    let shown = -1;
    const render = (t) => {
      if (t === shown) return;
      shown = t;
      strokes.forEach((stroke) => {
        const u = hand(t - stroke.start, stroke.time, RAMP * pace);
        if (u < 1) inkTo(stroke.el, u * stroke.units, stroke.units);
        else stroke.el.style.strokeDasharray = stroke.el.style.visibility = '';
      });
      fill(t >= total);
    };

    let frame = 0;
    signal.addEventListener('abort', () => cancelAnimationFrame(frame));

    // Tied to the scroll: the drawing follows where it sits on the screen, the pen gliding after it
    let target = 0;
    let last = 0;
    const place = () => {
      const box = root.getBoundingClientRect();
      const from = window.innerHeight * START; // its top there: nothing drawn
      const to = window.innerHeight * END - box.height / 2; // its top there: all drawn
      target = Math.min(Math.max((from - box.top) / (from - to), 0), 1) * total;
    };
    const follow = (now) => {
      const dt = Math.min(now - last, 50);
      last = now;
      render(penStep(shown, target, dt, FOLLOW * 1000, GLIDE));
      frame = shown === target ? 0 : requestAnimationFrame(follow);
    };
    const kick = () => {
      place();
      if (frame || shown === target) return;
      last = performance.now();
      frame = requestAnimationFrame(follow);
    };

    // On entering the screen: the pen starts once, from the first stroke. At the foot of a page
    // the drawing may never get that far up: once the page goes no further down, a drawing in
    // full view starts
    let seen = null;
    const wait = new AbortController();
    signal.addEventListener('abort', () => wait.abort());
    const play = () => {
      seen?.disconnect();
      wait.abort();
      cancelAnimationFrame(frame);
      const begin = performance.now();
      const tick = (now) => {
        render(Math.min(now - begin, total));
        frame = shown < total ? requestAnimationFrame(tick) : 0;
      };
      render(0);
      frame = requestAnimationFrame(tick);
    };

    time();
    if (scrolled) {
      place();
      render(target);
      window.addEventListener('scroll', kick, { passive: true, signal });
      window.addEventListener('resize', kick, { passive: true, signal });
    } else {
      render(0);
      seen = new IntersectionObserver((entries) => entries.some((entry) => entry.isIntersecting) && play(), {
        rootMargin: '0px 0px -15% 0px',
        threshold: 0.6,
      });
      seen.observe(root);
      signal.addEventListener('abort', () => seen.disconnect());
      const foot = () => {
        const box = root.getBoundingClientRect();
        const end = document.documentElement.scrollHeight - innerHeight - scrollY <= 1;
        if (end && box.height && box.top >= 0 && box.bottom <= innerHeight) play();
      };
      window.addEventListener('scroll', foot, { passive: true, signal: wait.signal });
      foot(); // a page too short to scroll never sends a scroll event
      root.addEventListener('kodza:replay', play, { signal });
    }

    // A new size changes how long each stroke is on screen (the pen's timing) and where it sits
    const resized = new ResizeObserver(() => {
      const done = shown >= total;
      time();
      if (scrolled) kick();
      else if (done) render(total);
    });
    resized.observe(root);
    signal.addEventListener('abort', () => resized.disconnect());
  }

  // ---------- Pen engine: the same block in Scroll Path, Path Draw and Annotation Arrow ----------
  // Boxes measured in a root's own pixels, a line inked by its length (stroke-dasharray: the `d`
  // of a path is never animated, Safari would not play it) and a pen that moves along it at a
  // steady speed. Nothing in it knows the component around it
  const NS = 'http://www.w3.org/2000/svg';
  const inOut = (t) => (t < 0.5 ? 4 * t * t * t : 1 - (-2 * t + 2) ** 3 / 2);
  // Where an element sits in `root`, in the root's own pixels: a parent scaled by transform (a
  // thumbnail, a theme) does not shift the drawing
  const boxesIn = (root) => {
    const box = root.getBoundingClientRect();
    const scale = box.width / root.offsetWidth || 1;
    return (el) => {
      const r = el.getBoundingClientRect();
      return { x: (r.left - box.left) / scale, y: (r.top - box.top) / scale, w: r.width / scale, h: r.height / scale };
    };
  };
  // Inks a shape up to `length` px along its outline (`total` px long)
  const inkTo = (el, length, total) => {
    el.style.strokeDasharray = `${length.toFixed(1)} ${Math.ceil(total + 2)}`;
    el.style.visibility = length > 0.5 ? '' : 'hidden';
  };
  // One frame of the pen (`dt` ms): from `shown` towards `target`, at most `speed` px a second,
  // a little faster when it lifts the ink off. `glide` eases it in (1: a steady speed)
  const penStep = (shown, target, dt, speed, glide = 1) => {
    const cap = ((speed * dt) / 1000) * (target < shown ? 1.5 : 1);
    const next = shown + Math.sign(target - shown) * Math.min(Math.abs(target - shown) * glide, cap);
    return Math.abs(target - next) < 0.5 ? target : next;
  };
  // ---------- End of the pen engine ----------


  // Kodza lifecycle, the same in every component: `kodza:init` starts the instances inside
  // event.detail.root (the whole page by default), `kodza:destroy` stops them and puts their
  // markup back. For themes and apps that swap content without a page load. Each running root
  // keeps its markup as written under KODZA, shared by every Kodza script on the page: a Kodza
  // component inside another one is saved as written, not half-started, and stopped with it. Two
  // components on one root (a reveal on a stat card) both start, and stop together.
  const KODZA = Symbol.for('kodza');
  const RUNNING = Symbol.for(`kodza ${SELECTOR}`); // a root this component runs on, for every copy of this script
  const instances = new WeakMap();
  const find = (scope = document) => [scope, ...scope.querySelectorAll(SELECTOR)].filter((el) => el.matches?.(SELECTOR));
  const attrsOf = (el) => [...el.attributes].map((a) => [a.name, a.value]);
  const put = (el, saved) => {
    [...el.attributes].forEach((a) => el.removeAttribute(a.name));
    saved.attrs.forEach(([name, value]) => el.setAttribute(name, value));
    el.innerHTML = saved.html;
  };
  // The markup inside a root as written: Kodza components already running in it give back their own
  const written = (root) => {
    const all = [...root.querySelectorAll('*')];
    if (!all.some((el) => el[KODZA])) return root.innerHTML;
    const copy = root.cloneNode(true);
    const twins = copy.querySelectorAll('*');
    let last = null;
    all.forEach((el, i) => {
      if (!el[KODZA] || last?.contains(el)) return;
      last = el;
      put(twins[i], el[KODZA]);
    });
    return copy.innerHTML;
  };
  const init = (scope) => find(scope).forEach((root) => {
    // Already running, maybe from another copy of this script. Marked is-ready with no Kodza component
    // running on it, a root is a copy of a started one (a cloned slide): it is left as it is
    if (root[RUNNING] || (root.classList.contains('is-ready') && !root[KODZA])) return;
    // Rendered by React (data-kodza-manual): React starts it, with an init aimed at that markup once
    // it has hydrated it. Any earlier start would change markup React has not taken over yet
    const owner = root.closest('[data-kodza-manual]');
    if (owner && !(scope && owner.contains(scope))) return;
    const controller = new AbortController();
    // Another Kodza component already running on this root: its markup as written is kept, and the
    // two stop together
    const before = root[KODZA];
    const saved = { html: before ? before.html : written(root), attrs: before ? before.attrs : attrsOf(root), stop: () => destroy(root) };
    if (before) before.above = saved;
    instances.set(root, { controller, saved, before });
    root[KODZA] = saved;
    root[RUNNING] = true;
    mount(root, controller.signal);
    root.classList.add('is-ready');
  });
  const destroy = (scope) => find(scope).forEach((root) => {
    const instance = instances.get(root);
    if (!instance) return;
    instances.delete(root);
    instance.saved.above?.stop(); // a Kodza component started after it on the same root stops first
    // The Kodza components running inside it stop first: once its markup is put back, their own
    // script could not find them any more
    root.querySelectorAll('*').forEach((el) => el[KODZA]?.stop());
    instance.controller.abort();
    delete root[RUNNING];
    // Started on top of another one: that one stops next, and puts the markup back
    if (instance.before) {
      delete instance.before.above;
      root[KODZA] = instance.before;
      return instance.before.stop();
    }
    delete root[KODZA];
    put(root, instance.saved);
  });
  document.addEventListener('kodza:init', (event) => init(event.detail?.root));
  document.addEventListener('kodza:destroy', (event) => destroy(event.detail?.root));
  init();
  // Loaded in <head>, the script runs before the markup exists: once more when it is parsed
  if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', () => init(), { once: true });
})();
```

Free to use, from Kodza (https://kodza.dev).
