# Morph Icons

> Icon buttons whose strokes travel into the other icon: play to pause, sound to mute, plus to close, list to grid. They follow aria-pressed or aria-expanded and fire kodza:morph-icons.

SVG & Drawing · svg, icon, icon button, toggle, morph, play pause, mute, plus close, grid view · HTML, CSS, vanilla JS · no dependencies · updated 2026-11-04
Demo: https://kodza.dev/components/morph-icons/
Source on GitHub: https://github.com/kodza-dev/kodza/tree/main/components/morph-icons

## Files

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

- [`kodza-morph-icons.css`](https://kodza.dev/registry/morph-icons/kodza-morph-icons.css) · 13.8 KB
- [`kodza-morph-icons.js`](https://kodza.dev/registry/morph-icons/kodza-morph-icons.js) · 5.2 KB
- [`kodza-morph-icons.html`](https://kodza.dev/registry/morph-icons/kodza-morph-icons.html) · 2.5 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-morph-icons.css https://kodza.dev/registry/morph-icons/kodza-morph-icons.css
curl -fsSL --create-dirs -o kodza/kodza-morph-icons.js https://kodza.dev/registry/morph-icons/kodza-morph-icons.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-morph-icons`
- Variables (set them on the root element itself: it declares its own defaults):
  - `--kz-morph-icons-size: 44px`
  - `--kz-morph-icons-icon: 20px`
  - `--kz-morph-icons-stroke: 1.75px` — in icon units, 24 across
  - `--kz-morph-icons-ink: #0a0a0a`
  - `--kz-morph-icons-on-ink: #ffffff`
  - `--kz-morph-icons-hover: #2a2a2a` — the circle under the pointer
  - `--kz-morph-icons-tint: rgba(10, 10, 10, 0.07)` — the bare button under the pointer
  - `--kz-morph-icons-duration: 0.45s`
  - `--kz-morph-icons-ease: cubic-bezier(0.65, 0, 0.35, 1)` — in and out, so the strokes are seen travelling
- Modifiers: `.kodza-morph-icons--bare`, `.kodza-morph-icons--play`, `.kodza-morph-icons--plus`, `.kodza-morph-icons--sound`, `.kodza-morph-icons--view`
- Events: `kodza:morph-icons` (bubbling, from the root)
- Lifecycle: `kodza:init` / `kodza:destroy` on `document`, with `{ detail: { root } }` to target a container.

## Keyboard

What each key does, by where the focus is. Keep it working when you adapt the HTML: same elements, same classes.

- On a button (focus in `.kodza-morph-icons`):
  - `Enter` / `Space`: Switches the icon, and aria-pressed or aria-expanded with it

## 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-morph-icons {
    --kz-morph-icons-ink: #f2f2f0;
    --kz-morph-icons-on-ink: #0a0a0a;
    --kz-morph-icons-hover: #ffffff;
    --kz-morph-icons-tint: rgba(255, 255, 255, 0.1);
  }
}
```

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

## Use it

### Plain HTML page

- CSS: `kodza/kodza-morph-icons.css` next to the page (the Files commands as they are), linked in `<head>`: `<link rel="stylesheet" href="kodza/kodza-morph-icons.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-morph-icons.js`, loaded with `<script src="kodza/kodza-morph-icons.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">`.
- Corners: a site with its own shapes sets them once for every Kodza component, on `:root`, never by editing the CSS (unset, nothing changes): `--kz-radius-pill` sets the pills (`0` squares them).
- 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-morph-icons.css' -e 'd' -e '}' -e '/^KODZA-JS$/{r kodza/kodza-morph-icons.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">`.
- Corners: a site with its own shapes sets them once for every Kodza component, on `:root`, never by editing the CSS (unset, nothing changes): `--kz-radius-pill` sets the pills (`0` squares them).
- 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 is inline (it flows like a word): pasted alone, many themes leave it at the edge of the page (block themes, and classic ones like Twenty Twenty-One or Blocksy), so put the Custom HTML block inside a **Group** block to line it up with the text.
- 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-morph-icons', $uri . 'kodza-morph-icons.css', [], filemtime($dir . 'kodza-morph-icons.css'));
    wp_enqueue_script('kodza-morph-icons', $uri . 'kodza-morph-icons.js', [], filemtime($dir . 'kodza-morph-icons.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.
- 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-morph-icons.css` and `assets/kodza-morph-icons.js` (the Files commands with `-o assets/…`).
- In the section: `{{ 'kodza-morph-icons.css' | asset_url | stylesheet_tag }}` and `<script src="{{ 'kodza-morph-icons.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/`): `MorphIcons.tsx` (below), the CSS block under Code saved as `morph-icons.css` and the JS block as `morph-icons.js`, both as they are. The HTML block is already inside the component: skip it.
- Use it: `import { MorphIcons } from '@/components/kodza/MorphIcons';` then `<MorphIcons />`. Props: `variant` ("bare", "play", "plus", "sound", "view", or several in an array), `vars` (the `--kz-…` variables listed under API, e.g. `vars={{ '--kz-morph-icons-size': … }}`), `onMorphIcons` (the `kodza:morph-icons` event), `className`, `style` and the other props of its `<button>` (`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 './morph-icons.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 — Morph Icons, for React. From https://kodza.dev/components/morph-icons/
// 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: morph-icons.css and morph-icons.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 './morph-icons.css';

type Variant = "bare" | "play" | "plus" | "sound" | "view";

export type MorphIconsProps = Omit<ComponentPropsWithoutRef<'button'>, "children" | "variant" | "vars" | "onMorphIcons"> & {
  /** Modifier class(es): .kodza-morph-icons--bare, .kodza-morph-icons--play, .kodza-morph-icons--plus, .kodza-morph-icons--sound, .kodza-morph-icons--view */
  variant?: Variant | Variant[];
  /** Settings, as CSS variables on the root */
  vars?: {
    /** default: 44px */
    "--kz-morph-icons-size"?: string | number;
    /** default: 20px */
    "--kz-morph-icons-icon"?: string | number;
    /** in icon units, 24 across — default: 1.75px */
    "--kz-morph-icons-stroke"?: string | number;
    /** default: #0a0a0a */
    "--kz-morph-icons-ink"?: string | number;
    /** default: #ffffff */
    "--kz-morph-icons-on-ink"?: string | number;
    /** the circle under the pointer — default: #2a2a2a */
    "--kz-morph-icons-hover"?: string | number;
    /** the bare button under the pointer — default: rgba(10, 10, 10, 0.07) */
    "--kz-morph-icons-tint"?: string | number;
    /** default: 0.45s */
    "--kz-morph-icons-duration"?: string | number;
    /** in and out, so the strokes are seen travelling — default: cubic-bezier(0.65, 0, 0.35, 1) */
    "--kz-morph-icons-ease"?: string | number;
  };
  /** "kodza:morph-icons", fired by the script (bubbles from the root) */
  onMorphIcons?: (event: CustomEvent) => void;
  className?: string;
};

export function MorphIcons({ variant, vars, onMorphIcons, className, style, ...rest }: MorphIconsProps) {
  const ref = useRef<ComponentRef<'button'>>(null);
  const classes = ["kodza-morph-icons", "kodza-morph-icons--play", ...([] as string[]).concat(variant ?? []).map((v) => `kodza-morph-icons--${v}`), 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('./morph-icons.js').then(() => {
      if (live) document.dispatchEvent(new CustomEvent('kodza:init', { detail: { root } }));
    });
    return () => {
      live = false;
      document.dispatchEvent(new CustomEvent('kodza:destroy', { detail: { root } }));
    };
  }, [key]);

  useEffect(() => {
    const root = ref.current;
    if (!root || !onMorphIcons) return;
    const listener = (event: Event) => onMorphIcons(event as CustomEvent);
    root.addEventListener("kodza:morph-icons", listener);
    return () => root.removeEventListener("kodza:morph-icons", listener);
  }, [onMorphIcons, key]);

  return (
    <button type="button" aria-pressed="false" aria-label="Play" key={key} {...rest} className={classes} data-kodza-manual style={{ ...vars, ...style } as CSSProperties} ref={ref}>
      <svg viewBox="0 0 24 24" aria-hidden="true" focusable="false">
        <path className="kodza-morph-icons__s kodza-morph-icons__edge" d="M-12 0H12" />
        <path className="kodza-morph-icons__s kodza-morph-icons__upper" d="M-12 0H12" />
        <path className="kodza-morph-icons__s kodza-morph-icons__lower" d="M-12 0H12" />
      </svg>
    </button>
  );
}
```

## Code

```html
<button class="kodza-morph-icons kodza-morph-icons--play" type="button" aria-pressed="false" aria-label="Play">
  <svg viewBox="0 0 24 24" aria-hidden="true" focusable="false">
    <path class="kodza-morph-icons__s kodza-morph-icons__edge" d="M-12 0H12"/>
    <path class="kodza-morph-icons__s kodza-morph-icons__upper" d="M-12 0H12"/>
    <path class="kodza-morph-icons__s kodza-morph-icons__lower" d="M-12 0H12"/>
  </svg>
</button>

<button class="kodza-morph-icons kodza-morph-icons--sound" type="button" aria-pressed="false" aria-label="Mute">
  <svg viewBox="0 0 24 24" aria-hidden="true" focusable="false">
    <path d="M3 9.5H6.5L11 5.5V18.5L6.5 14.5H3Z"/>
    <path class="kodza-morph-icons__s kodza-morph-icons__wave" d="M14.5 9A4 4 0 0 1 14.5 15"/>
    <path class="kodza-morph-icons__s kodza-morph-icons__wave kodza-morph-icons__wave--far" d="M17.5 6A7 7 0 0 1 17.5 18"/>
    <path class="kodza-morph-icons__s kodza-morph-icons__cross" d="M-12 0H12"/>
    <path class="kodza-morph-icons__s kodza-morph-icons__cross kodza-morph-icons__cross--back" d="M-12 0H12"/>
  </svg>
</button>

<button class="kodza-morph-icons kodza-morph-icons--plus" type="button" aria-expanded="false" aria-label="Filters">
  <svg viewBox="0 0 24 24" aria-hidden="true" focusable="false">
    <path class="kodza-morph-icons__s kodza-morph-icons__bar" d="M-12 0H12"/>
    <path class="kodza-morph-icons__s kodza-morph-icons__bar kodza-morph-icons__bar--upright" d="M-12 0H12"/>
  </svg>
</button>

<button class="kodza-morph-icons kodza-morph-icons--view kodza-morph-icons--bare" type="button" aria-pressed="false" aria-label="Grid view">
  <svg viewBox="0 0 24 24" aria-hidden="true" focusable="false">
    <g class="kodza-morph-icons__row">
      <rect x="4" y="4" width="6" height="6"/>
      <path class="kodza-morph-icons__s kodza-morph-icons__top" d="M-12 0H12"/>
      <path class="kodza-morph-icons__s kodza-morph-icons__bottom" d="M-12 0H12"/>
      <path class="kodza-morph-icons__s kodza-morph-icons__side" d="M-12 0H12"/>
      <path class="kodza-morph-icons__s kodza-morph-icons__side kodza-morph-icons__side--end" d="M-12 0H12"/>
    </g>
    <g class="kodza-morph-icons__row">
      <rect x="4" y="4" width="6" height="6"/>
      <path class="kodza-morph-icons__s kodza-morph-icons__top" d="M-12 0H12"/>
      <path class="kodza-morph-icons__s kodza-morph-icons__bottom" d="M-12 0H12"/>
      <path class="kodza-morph-icons__s kodza-morph-icons__side" d="M-12 0H12"/>
      <path class="kodza-morph-icons__s kodza-morph-icons__side kodza-morph-icons__side--end" d="M-12 0H12"/>
    </g>
  </svg>
</button>
```

```css
/* Kodza License: free to use, client work included. Not to resell or redistribute, ported or not: https://kodza.dev/docs/#print-license */
/* Kodza — Morph Icons
   Icon buttons that change their mind: the strokes of one icon travel, turn and shorten into the
   other. Play folds into pause, the sound waves fade out under a cross, plus turns into close, the
   list closes up into a grid. Nothing is swapped: the same strokes move. Each one is a straight
   line placed by a transform and cut by stroke-dasharray, never an animated d, so Safari plays it.
   The state is the button's own aria-pressed (aria-expanded on a disclosure): the script flips it
   on click, and so can yours. The first icon shows while it is false, the second while it is true.
   Everything is tuned with the --kz-morph-icons-* variables. */
.kodza-morph-icons {
  --kz-morph-icons-size: 44px;
  --kz-morph-icons-icon: 20px;
  --kz-morph-icons-stroke: 1.75px; /* in icon units, 24 across */
  --kz-morph-icons-ink: #0a0a0a;
  --kz-morph-icons-on-ink: #ffffff;
  --kz-morph-icons-hover: #2a2a2a; /* the circle under the pointer */
  --kz-morph-icons-tint: rgba(10, 10, 10, 0.07); /* the bare button under the pointer */
  --kz-morph-icons-duration: 0.45s;
  --kz-morph-icons-ease: cubic-bezier(0.65, 0, 0.35, 1); /* in and out, so the strokes are seen travelling */

  display: inline-grid;
  flex: none;
  place-items: center;
  box-sizing: border-box;
  width: var(--kz-morph-icons-size);
  height: var(--kz-morph-icons-size);
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: var(--kz-radius-pill, 999px);
  background: var(--kz-morph-icons-ink);
  color: var(--kz-morph-icons-on-ink);
  font: inherit;
  line-height: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition:
    background-color calc(0.2s * var(--kz-motion-scale, 1)) ease,
    scale calc(0.15s * var(--kz-motion-scale, 1)) cubic-bezier(0.22, 1, 0.36, 1);
}

.kodza-morph-icons:focus-visible {
  outline: 2px solid var(--kz-morph-icons-ink);
  outline-offset: 3px;
}

.kodza-morph-icons:active {
  scale: 0.92;
}

/* Bare: no circle, for a toolbar that keeps its buttons plain */
.kodza-morph-icons--bare {
  background: transparent;
  color: var(--kz-morph-icons-ink);
}

@media (hover: hover) {
  .kodza-morph-icons:hover {
    background: var(--kz-morph-icons-hover);
  }

  .kodza-morph-icons--bare:hover {
    background: var(--kz-morph-icons-tint);
  }
}

.kodza-morph-icons svg {
  display: block;
  width: var(--kz-morph-icons-icon);
  height: var(--kz-morph-icons-icon);
  overflow: hidden;
  fill: none;
  stroke: currentColor;
  stroke-width: var(--kz-morph-icons-stroke);
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

/* Every moving stroke is the same 24-unit line, M-12 0H12. A transform puts its middle in place and
   turns it; the dash shows L units of it around that middle: dasharray L 48, offset L/2 - 12.
   A stroke that goes away shrinks to its middle and thins out with it, so its round cap never
   stays behind as a dot; one that comes back grows the same way, from nothing. */
.kodza-morph-icons__s {
  transform-box: view-box;
  transform-origin: 0 0;
  transition-property: transform, stroke-dasharray, stroke-dashoffset, stroke-width;
  transition-duration: 0s;
  transition-timing-function: var(--kz-morph-icons-ease);
}

/* Motion starts once the script is ready, so nothing moves on load */
.kodza-morph-icons.is-ready .kodza-morph-icons__s {
  transition-duration: calc(var(--kz-morph-icons-duration) * var(--kz-motion-scale, 1));
}

/* Play ↔ pause: the left edge steps right and stays a bar; the two slopes stand up and shorten into
   the second bar. Give it aria-label "Play": aria-pressed is true while it plays, and shows pause */
.kodza-morph-icons--play .kodza-morph-icons__edge {
  transform: translate(8px, 12px) rotate(90deg);
  stroke-dasharray: 12px 48px;
  stroke-dashoffset: -6px;
}

.kodza-morph-icons--play .kodza-morph-icons__upper {
  transform: translate(13px, 9px) rotate(30.964deg);
  stroke-dasharray: 11.662px 48px;
  stroke-dashoffset: -6.169px;
}

.kodza-morph-icons--play .kodza-morph-icons__lower {
  transform: translate(13px, 15px) rotate(-30.964deg);
  stroke-dasharray: 11.662px 48px;
  stroke-dashoffset: -6.169px;
}

.kodza-morph-icons--play:is([aria-pressed="true"], [aria-expanded="true"]) .kodza-morph-icons__edge {
  transform: translate(9px, 12px) rotate(90deg);
}

.kodza-morph-icons--play:is([aria-pressed="true"], [aria-expanded="true"]) .kodza-morph-icons__upper {
  transform: translate(15px, 9px) rotate(90deg);
  stroke-dasharray: 6px 48px;
  stroke-dashoffset: -9px;
}

.kodza-morph-icons--play:is([aria-pressed="true"], [aria-expanded="true"]) .kodza-morph-icons__lower {
  transform: translate(15px, 15px) rotate(-90deg);
  stroke-dasharray: 6px 48px;
  stroke-dashoffset: -9px;
}

/* Sound ↔ mute: the far wave fades out first, then the near one, each shrinking to its middle,
   and a cross grows where they were; unmuting plays it backwards. Give it aria-label "Mute" */
.kodza-morph-icons--sound .kodza-morph-icons__wave {
  stroke-dasharray: 6.79px 24px; /* the near arc is 6.78 long */
  stroke-dashoffset: 0;
  transition-delay: calc(var(--kz-morph-icons-duration) * 0.25 * var(--kz-motion-scale, 1));
}

.kodza-morph-icons--sound .kodza-morph-icons__wave--far {
  stroke-dasharray: 14.42px 24px; /* the far arc is 14.42 long */
  transition-delay: calc(var(--kz-morph-icons-duration) * 0.35 * var(--kz-motion-scale, 1));
}

.kodza-morph-icons--sound .kodza-morph-icons__cross {
  transform: translate(17px, 12px) rotate(45deg);
  stroke-dasharray: 0px 48px;
  stroke-dashoffset: -12px;
  stroke-width: 0;
}

.kodza-morph-icons--sound .kodza-morph-icons__cross--back {
  transform: translate(17px, 12px) rotate(-45deg);
}

.kodza-morph-icons--sound:is([aria-pressed="true"], [aria-expanded="true"]) .kodza-morph-icons__wave {
  stroke-dasharray: 0px 24px;
  stroke-dashoffset: -3.39px;
  stroke-width: 0;
  transition-delay: calc(var(--kz-morph-icons-duration) * 0.08 * var(--kz-motion-scale, 1));
}

.kodza-morph-icons--sound:is([aria-pressed="true"], [aria-expanded="true"]) .kodza-morph-icons__wave--far {
  stroke-dashoffset: -7.21px;
  transition-delay: 0s;
}

.kodza-morph-icons--sound:is([aria-pressed="true"], [aria-expanded="true"]) .kodza-morph-icons__cross {
  stroke-dasharray: 8.485px 48px;
  stroke-dashoffset: -7.757px;
  stroke-width: var(--kz-morph-icons-stroke);
  transition-delay: calc(var(--kz-morph-icons-duration) * 0.3 * var(--kz-motion-scale, 1));
}

.kodza-morph-icons--sound:is([aria-pressed="true"], [aria-expanded="true"]) .kodza-morph-icons__cross--back {
  transition-delay: calc(var(--kz-morph-icons-duration) * 0.38 * var(--kz-motion-scale, 1));
}

/* Plus ↔ close: both bars turn a quarter of the way round and lengthen a little, since a cross
   looks smaller than a plus of the same length. On a disclosure, use aria-expanded */
.kodza-morph-icons--plus .kodza-morph-icons__bar {
  transform: translate(12px, 12px) rotate(0deg);
  stroke-dasharray: 14px 48px;
  stroke-dashoffset: -5px;
}

.kodza-morph-icons--plus .kodza-morph-icons__bar--upright {
  transform: translate(12px, 12px) rotate(90deg);
}

.kodza-morph-icons--plus:is([aria-pressed="true"], [aria-expanded="true"]) .kodza-morph-icons__bar {
  transform: translate(12px, 12px) rotate(45deg);
  stroke-dasharray: 16px 48px;
  stroke-dashoffset: -4px;
}

.kodza-morph-icons--plus:is([aria-pressed="true"], [aria-expanded="true"]) .kodza-morph-icons__bar--upright {
  transform: translate(12px, 12px) rotate(135deg);
}

/* List ↔ grid: each row keeps its tile; the two lines beside it slide apart into the top and bottom
   of a second tile, and its sides grow between them. The second row follows a beat later.
   Give it aria-label "Grid view" */
.kodza-morph-icons__row {
  --kz-morph-icons-row: 0;
  transform-box: view-box;
  transform-origin: 0 0;
}

.kodza-morph-icons__row + .kodza-morph-icons__row {
  --kz-morph-icons-row: 1;
  transform: translateY(10px);
}

.kodza-morph-icons--view .kodza-morph-icons__top {
  transform: translate(17px, 5px) rotate(0deg);
  stroke-dasharray: 6px 48px;
  stroke-dashoffset: -9px;
  transition-delay: calc(var(--kz-morph-icons-duration) * (0.15 + 0.06 * var(--kz-morph-icons-row)) * var(--kz-motion-scale, 1));
}

.kodza-morph-icons--view .kodza-morph-icons__bottom {
  transform: translate(16px, 9px) rotate(0deg);
  stroke-dasharray: 4px 48px;
  stroke-dashoffset: -10px;
  transition-delay: calc(var(--kz-morph-icons-duration) * (0.15 + 0.06 * var(--kz-morph-icons-row)) * var(--kz-motion-scale, 1));
}

.kodza-morph-icons--view .kodza-morph-icons__side {
  transform: translate(14px, 7px) rotate(90deg);
  stroke-dasharray: 0px 48px;
  stroke-dashoffset: -12px;
  stroke-width: 0;
  transition-delay: calc(var(--kz-morph-icons-duration) * 0.06 * var(--kz-morph-icons-row) * var(--kz-motion-scale, 1));
}

.kodza-morph-icons--view .kodza-morph-icons__side--end {
  transform: translate(20px, 7px) rotate(90deg);
}

.kodza-morph-icons--view:is([aria-pressed="true"], [aria-expanded="true"]) .kodza-morph-icons__top {
  transform: translate(17px, 4px) rotate(0deg);
  transition-delay: calc(var(--kz-morph-icons-duration) * 0.06 * var(--kz-morph-icons-row) * var(--kz-motion-scale, 1));
}

.kodza-morph-icons--view:is([aria-pressed="true"], [aria-expanded="true"]) .kodza-morph-icons__bottom {
  transform: translate(17px, 10px) rotate(0deg);
  stroke-dasharray: 6px 48px;
  stroke-dashoffset: -9px;
  transition-delay: calc(var(--kz-morph-icons-duration) * 0.06 * var(--kz-morph-icons-row) * var(--kz-motion-scale, 1));
}

.kodza-morph-icons--view:is([aria-pressed="true"], [aria-expanded="true"]) .kodza-morph-icons__side {
  stroke-dasharray: 6px 48px;
  stroke-dashoffset: -9px;
  stroke-width: var(--kz-morph-icons-stroke);
  transition-delay: calc(var(--kz-morph-icons-duration) * (0.2 + 0.06 * var(--kz-morph-icons-row)) * var(--kz-motion-scale, 1));
}

@media (prefers-reduced-motion: reduce) {
  .kodza-morph-icons,
  .kodza-morph-icons *,
  .kodza-morph-icons *::before,
  .kodza-morph-icons *::after {
    transition-duration: 0.01ms !important;
    transition-delay: 0s !important;
    animation-duration: 0.01ms !important;
  }
}

/* kodza-guard 553d6022bf74 — 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, where the component sets it only in some states: at the lowest weight, so its own rules below put it back */

:where(.kodza-morph-icons):not(#_) {
  outline: revert;
  outline-offset: revert;
}

:where(.kodza-morph-icons svg:where(:not([class*="kodza-"]))):not(#_) {
  transition-duration: revert;
  transition-delay: revert;
}

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

.kodza-morph-icons:not(#_) {
  text-decoration: revert;
  list-style: revert;
  position: revert;
  box-shadow: revert;
  appearance: revert;
  max-height: revert;
  letter-spacing: revert;
  text-transform: revert;
  text-underline-offset: revert;
  text-align: revert;
  text-indent: revert;
  text-shadow: revert;
  vertical-align: revert;
  white-space: revert;
  min-height: revert;
}

.kodza-morph-icons__s:not(#_),
.kodza-morph-icons__row:not(#_) {
  box-sizing: revert;
}

.kodza-morph-icons svg:where(:not([class*="kodza-"])):not(#_) {
  border: revert;
  margin: revert;
  padding: revert;
  border-radius: revert;
  outline: revert;
  text-decoration: 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-width: 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;
  transition-property: revert;
  transition-timing-function: 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-morph-icons:not(#_) {
  display: inline-grid;
  flex: none;
  place-items: center;
  box-sizing: border-box;
  width: var(--kz-morph-icons-size);
  height: var(--kz-morph-icons-size);
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: var(--kz-radius-pill, 999px);
  background: var(--kz-morph-icons-ink);
  color: var(--kz-morph-icons-on-ink);
  font: inherit;
  line-height: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color calc(0.2s * var(--kz-motion-scale, 1)) ease,
    scale calc(0.15s * var(--kz-motion-scale, 1)) cubic-bezier(0.22, 1, 0.36, 1);
}

.kodza-morph-icons:focus-visible:not(#_) {
  outline: 2px solid var(--kz-morph-icons-ink);
  outline-offset: 3px;
}

.kodza-morph-icons:active:not(#_) {
  scale: 0.92;
}

.kodza-morph-icons--bare:not(#_) {
  background: transparent;
  color: var(--kz-morph-icons-ink);
}

@media (hover: hover) {
  .kodza-morph-icons:hover:not(#_) {
    background: var(--kz-morph-icons-hover);
  }
}

@media (hover: hover) {
  .kodza-morph-icons--bare:hover:not(#_) {
    background: var(--kz-morph-icons-tint);
  }
}

.kodza-morph-icons svg:not(#_) {
  display: block;
}

@media (prefers-reduced-motion: reduce) {
  .kodza-morph-icons:not(#_) {
    transition-duration: 0.01ms !important;
    transition-delay: 0s !important;
    animation-duration: 0.01ms !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  .kodza-morph-icons *:where(svg):not(#_) {
    transition-duration: 0.01ms !important;
    transition-delay: 0s !important;
  }
}
```

```js
// Kodza License: free to use, client work included. Not to resell or redistribute, ported or not: https://kodza.dev/docs/#print-license
// Kodza — Morph Icons
// The CSS draws both icons and plays the morph; the script only flips the state on click:
// aria-expanded when the button has it (it opens something), aria-pressed otherwise. Your own code
// can set the same attribute (a player that starts on its own), and the icon follows. Each click
// sends a kodza:morph-icons event, detail { pressed }, that bubbles.
(() => {
  const SELECTOR = '.kodza-morph-icons';

  // One instance, with its own state: two copies on a page never interfere. Everything it
  // starts is tied to `signal` (listeners get { signal }, observers and timers stop on its
  // 'abort' event), so kodza:destroy stops it all.
  function mount(root, signal) {
    const attr = root.hasAttribute('aria-expanded') ? 'aria-expanded' : 'aria-pressed';
    if (!root.hasAttribute(attr)) root.setAttribute(attr, 'false');
    root.addEventListener('click', () => {
      const pressed = root.getAttribute(attr) !== 'true';
      root.setAttribute(attr, String(pressed));
      root.dispatchEvent(new CustomEvent('kodza:morph-icons', { bubbles: true, detail: { pressed } }));
    }, { signal });
  }

  // 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).
