# Footnote Link

> Footnotes that stay on their line. Wide, the note sits in the margin level with its line and inks with its number; narrow, it folds out under the line. Picks up WordPress footnotes as they are.

Links · link, footnote, sidenote, article, typography, wordpress · HTML, CSS, vanilla JS · no dependencies · updated 2026-10-26
Demo: https://kodza.dev/components/footnote-link/
Source on GitHub: https://github.com/kodza-dev/kodza/tree/main/components/footnote-link

## Files

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

- [`kodza-footnote-link.css`](https://kodza.dev/registry/footnote-link/kodza-footnote-link.css) · 12.6 KB
- [`kodza-footnote-link.js`](https://kodza.dev/registry/footnote-link/kodza-footnote-link.js) · 11.3 KB
- [`kodza-footnote-link.html`](https://kodza.dev/registry/footnote-link/kodza-footnote-link.html) · 1.2 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-footnote-link.css https://kodza.dev/registry/footnote-link/kodza-footnote-link.css
curl -fsSL --create-dirs -o kodza/kodza-footnote-link.js https://kodza.dev/registry/footnote-link/kodza-footnote-link.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: `[data-kodza-footnote-link]`
- Variables (set them on the root element itself: it declares its own defaults):
  - `--kz-footnote-link-ink: #0a0a0a`
  - `--kz-footnote-link-paper: #fff`
  - `--kz-footnote-link-muted: rgba(10, 10, 10, 0.62)`
  - `--kz-footnote-link-sheet: rgba(10, 10, 10, 0.05)`
  - `--kz-footnote-link-note-width: 210px`
  - `--kz-footnote-link-gap: 48px`
  - `--kz-footnote-link-note-size: 0.82em`
  - `--kz-footnote-link-duration: 0.26s`
  - `--kz-footnote-link-ease: cubic-bezier(0.22, 1, 0.36, 1)`
- Attributes:
  - `data-kodza-footnote-link`
- 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 note number (focus in `.kodza-footnote-link__ref`):
  - `Enter` / `Space`: Opens or closes the note, or inks it in the margin
  - `Escape`: Closes the note, or lets go of the ink

## 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-footnote-link {
    --kz-footnote-link-ink: #f2f2f0;
    --kz-footnote-link-paper: #0a0a0a;
    --kz-footnote-link-muted: rgba(242, 242, 240, 0.62);
    --kz-footnote-link-sheet: rgba(255, 255, 255, 0.08);
  }
}
```

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

## Use it

### Plain HTML page

- CSS: `kodza/kodza-footnote-link.css` next to the page (the Files commands as they are), linked in `<head>`: `<link rel="stylesheet" href="kodza/kodza-footnote-link.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-footnote-link.js`, loaded with `<script src="kodza/kodza-footnote-link.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">`.
- 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-footnote-link.css' -e 'd' -e '}' -e '/^KODZA-JS$/{r kodza/kodza-footnote-link.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">`.
- 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.
- 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-footnote-link', $uri . 'kodza-footnote-link.css', [], filemtime($dir . 'kodza-footnote-link.css'));
    wp_enqueue_script('kodza-footnote-link', $uri . 'kodza-footnote-link.js', [], filemtime($dir . 'kodza-footnote-link.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. This one reads the page around it, and a script in the widget runs before the rest of the page exists: put its `<script>` in an HTML widget at the bottom of the page instead.

### Shopify

- Files: `assets/kodza-footnote-link.css` and `assets/kodza-footnote-link.js` (the Files commands with `-o assets/…`).
- In the section: `{{ 'kodza-footnote-link.css' | asset_url | stylesheet_tag }}` and `<script src="{{ 'kodza-footnote-link.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/`): `FootnoteLink.tsx` (below), the CSS block under Code saved as `footnote-link.css` and the JS block as `footnote-link.js`, both as they are. The HTML block is already inside the component: skip it.
- Use it: `import { FootnoteLink } from '@/components/kodza/FootnoteLink';` then `<FootnoteLink />`. Props: `vars` (the `--kz-…` variables listed under API, e.g. `vars={{ '--kz-footnote-link-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 './footnote-link.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 — Footnote Link, for React. From https://kodza.dev/components/footnote-link/
// 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: footnote-link.css and footnote-link.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.
// 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 './footnote-link.css';

export type FootnoteLinkProps = Omit<ComponentPropsWithoutRef<'div'>, "children" | "vars"> & {
  /** Settings, as CSS variables on the root */
  vars?: {
    /** default: #0a0a0a */
    "--kz-footnote-link-ink"?: string | number;
    /** default: #fff */
    "--kz-footnote-link-paper"?: string | number;
    /** default: rgba(10, 10, 10, 0.62) */
    "--kz-footnote-link-muted"?: string | number;
    /** default: rgba(10, 10, 10, 0.05) */
    "--kz-footnote-link-sheet"?: string | number;
    /** default: 210px */
    "--kz-footnote-link-note-width"?: string | number;
    /** default: 48px */
    "--kz-footnote-link-gap"?: string | number;
    /** default: 0.82em */
    "--kz-footnote-link-note-size"?: string | number;
    /** default: 0.26s */
    "--kz-footnote-link-duration"?: string | number;
    /** default: cubic-bezier(0.22, 1, 0.36, 1) */
    "--kz-footnote-link-ease"?: string | number;
  };
  className?: string;
};

export function FootnoteLink({ vars, className, style, ...rest }: FootnoteLinkProps) {
  const ref = useRef<ComponentRef<'div'>>(null);
  const classes = ["kodza-footnote-link", 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('./footnote-link.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 data-kodza-footnote-link="" key={key} {...rest} className={classes} style={{ ...vars, ...style } as CSSProperties} ref={ref}>
      <p>We shipped the redesign on a Friday at 4:40 pm.<button type="button" className="kodza-footnote-link__ref">1</button><span className="kodza-footnote-link__note">Yes, on purpose. Monday deploys only feel safer because nobody is looking.</span> Nothing broke. The new header, the pricing page and thirty-one components went out in one deploy, and the error graph stayed flat all weekend.</p>
      <p>The rollback plan fit in one command,<button type="button" className="kodza-footnote-link__ref">2</button><span className="kodza-footnote-link__note">git revert on the merge commit, then a push. The pipeline does the rest.</span> and nobody had to run it. We had rehearsed it twice on staging, timed it, and written the number down: ninety seconds from the first alert to the old site.</p>
      <p>The trick wasn't courage. It was a diff small enough to review in one sitting:<button type="button" className="kodza-footnote-link__ref">3</button><span className="kodza-footnote-link__note">If the review needs a meeting, the diff is too big. That's the whole rule.</span> forty lines per pull request, one reviewer each, and a test that failed before it passed.</p>
    </div>
  );
}
```

## Code

```html
<div class="kodza-footnote-link" data-kodza-footnote-link>
  <p>We shipped the redesign on a Friday at 4:40 pm.<button type="button" class="kodza-footnote-link__ref">1</button><span class="kodza-footnote-link__note">Yes, on purpose. Monday deploys only feel safer because nobody is looking.</span> Nothing broke. The new header, the pricing page and thirty-one components went out in one deploy, and the error graph stayed flat all weekend.</p>
  <p>The rollback plan fit in one command,<button type="button" class="kodza-footnote-link__ref">2</button><span class="kodza-footnote-link__note">git revert on the merge commit, then a push. The pipeline does the rest.</span> and nobody had to run it. We had rehearsed it twice on staging, timed it, and written the number down: ninety seconds from the first alert to the old site.</p>
  <p>The trick wasn't courage. It was a diff small enough to review in one sitting:<button type="button" class="kodza-footnote-link__ref">3</button><span class="kodza-footnote-link__note">If the review needs a meeting, the diff is too big. That's the whole rule.</span> forty lines per pull request, one reviewer each, and a test that failed before it passed.</p>
</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 — Footnote Link
   Footnotes that stay on their line. In a wide column the note sits in the margin, level with
   its line, and the number and the note ink together; in a narrow one a tap folds the note out
   under the line and the text slides down. Without the script, every note stays readable.
   Everything is tuned with the --kz-footnote-link-* variables. */
.kodza-footnote-link {
  --kz-footnote-link-ink: #0a0a0a;
  --kz-footnote-link-paper: #fff;
  --kz-footnote-link-muted: rgba(10, 10, 10, 0.62);
  --kz-footnote-link-sheet: rgba(10, 10, 10, 0.05);
  --kz-footnote-link-note-width: 210px;
  --kz-footnote-link-gap: 48px;
  --kz-footnote-link-note-size: 0.82em;
  --kz-footnote-link-duration: 0.26s;
  --kz-footnote-link-ease: cubic-bezier(0.22, 1, 0.36, 1);

  container: kodza-footnote-link / inline-size;
  display: flow-root;
  counter-reset: kodza-footnote-link;
}

/* The paragraphs it holds: their own spacing, whatever the theme gives to p */
.kodza-footnote-link > p {
  margin: 0 0 1.1em;
}

.kodza-footnote-link > p:last-child {
  margin-bottom: 0;
}

/* The number in the text: a small mono pill, raised without making its line taller */
.kodza-footnote-link__ref {
  position: relative;
  top: -0.5em;
  display: inline-block;
  box-sizing: border-box;
  min-width: 1.7em;
  height: 1.6em;
  margin: 0 0.1em 0 0.2em;
  padding: 0 0.45em;
  border: 0;
  border-radius: 999px;
  background: var(--kz-footnote-link-sheet);
  color: var(--kz-footnote-link-muted);
  font: 500 0.62em/1.6em "Geist Mono", ui-monospace, "SF Mono", Menlo, monospace;
  letter-spacing: 0;
  text-align: center;
  text-transform: none;
  vertical-align: baseline;
  cursor: pointer;
  counter-increment: kodza-footnote-link;
  -webkit-tap-highlight-color: transparent;
}

/* A target of 24 px at least, more under a finger */
.kodza-footnote-link__ref::before {
  content: "";
  position: absolute;
  inset: -4px;
}

@media (pointer: coarse) {
  .kodza-footnote-link__ref::before {
    inset: -10px -8px;
  }
}

.kodza-footnote-link__ref:focus-visible {
  outline: 2px solid var(--kz-footnote-link-ink);
  outline-offset: 2px;
}

/* The word before a number, the number and its note, kept on one line by the script */
.kodza-footnote-link__tie {
  white-space: nowrap;
}

/* The note. Narrow column (and the default): a sheet under the line, the text flows below it */
.kodza-footnote-link__note {
  --kz-footnote-link-pad-top: 12px;

  position: relative;
  white-space: normal;
  float: left;
  clear: both;
  box-sizing: border-box;
  width: 100%;
  margin: 0.55em 0 0.9em;
  padding: var(--kz-footnote-link-pad-top) 16px 13px 46px;
  border-radius: 12px;
  background: var(--kz-footnote-link-sheet);
  color: var(--kz-footnote-link-ink);
  font-size: var(--kz-footnote-link-note-size);
  line-height: 1.55;
  text-wrap: pretty;
}

/* Its number, the same pill as in the text, centred on the first line */
.kodza-footnote-link__note::before,
.kodza-footnote-link.is-ready .kodza-footnote-link__note::after {
  position: absolute;
  top: calc(var(--kz-footnote-link-pad-top) + 0.225em);
  left: 16px;
  box-sizing: border-box;
  min-width: 1.7em;
  height: 1.6em;
  padding: 0 0.45em;
  border-radius: 999px;
  font: 500 0.756em/1.6em "Geist Mono", ui-monospace, "SF Mono", Menlo, monospace;
  letter-spacing: 0;
  text-align: center;
}

.kodza-footnote-link__note::before {
  content: counter(kodza-footnote-link);
  background: var(--kz-footnote-link-sheet);
  color: var(--kz-footnote-link-muted);
}

.kodza-footnote-link.is-ready .kodza-footnote-link__note::before {
  content: attr(data-n);
}

/* Folded until its number is pressed, once the script runs */
@container kodza-footnote-link (max-width: 759.98px) {
  .kodza-footnote-link.is-ready .kodza-footnote-link__note:not(.is-open) {
    display: none;
  }
}

.kodza-footnote-link__note.is-moving {
  overflow: hidden;
}

/* Wide column: the text keeps a margin on its right, and each note sits there, level with its
   line. Notes close together stack instead of overlapping. */
@container kodza-footnote-link (min-width: 760px) {
  .kodza-footnote-link > * {
    padding-right: calc(var(--kz-footnote-link-note-width) + var(--kz-footnote-link-gap));
  }

  .kodza-footnote-link__note {
    --kz-footnote-link-pad-top: 0px;

    float: right;
    clear: right;
    width: var(--kz-footnote-link-note-width);
    margin: 0.3em calc(-1 * (var(--kz-footnote-link-note-width) + var(--kz-footnote-link-gap))) 1em 0;
    padding: 0 0 0 2.1em;
    border-radius: 0;
    background: none;
    color: var(--kz-footnote-link-muted);
  }

  .kodza-footnote-link__note::before,
  .kodza-footnote-link.is-ready .kodza-footnote-link__note::after {
    left: 0;
  }
}

/* The ink: a double of the number, ink on paper, uncovered from the bottom up. It rises in the
   number and in its note at the same time */
.kodza-footnote-link.is-ready .kodza-footnote-link__ref::after,
.kodza-footnote-link.is-ready .kodza-footnote-link__note::after {
  content: attr(data-n);
  background: var(--kz-footnote-link-ink);
  color: var(--kz-footnote-link-paper);
  clip-path: inset(100% 0 0 0);
  pointer-events: none;
  transition: clip-path var(--kz-footnote-link-duration) var(--kz-footnote-link-ease);
}

.kodza-footnote-link.is-ready .kodza-footnote-link__ref::after {
  position: absolute;
  inset: 0;
  border-radius: inherit;
}

.kodza-footnote-link.is-ready .kodza-footnote-link__note {
  transition: color 0.2s ease;
}

.kodza-footnote-link.is-ready .kodza-footnote-link__ref:focus-visible::after,
.kodza-footnote-link.is-ready .kodza-footnote-link__ref.is-active::after,
.kodza-footnote-link.is-ready .kodza-footnote-link__ref[aria-expanded="true"]::after,
.kodza-footnote-link.is-ready .kodza-footnote-link__ref:focus-visible + .kodza-footnote-link__note::after,
.kodza-footnote-link.is-ready .kodza-footnote-link__ref.is-active + .kodza-footnote-link__note::after,
.kodza-footnote-link.is-ready .kodza-footnote-link__ref[aria-expanded="true"] + .kodza-footnote-link__note::after {
  clip-path: inset(0);
}

.kodza-footnote-link.is-ready .kodza-footnote-link__ref:focus-visible + .kodza-footnote-link__note,
.kodza-footnote-link.is-ready .kodza-footnote-link__ref.is-active + .kodza-footnote-link__note {
  color: var(--kz-footnote-link-ink);
}

/* Pointing at the number or at its note inks both */
@media (hover: hover) {
  .kodza-footnote-link.is-ready .kodza-footnote-link__ref:hover::after,
  .kodza-footnote-link.is-ready .kodza-footnote-link__ref:has(+ .kodza-footnote-link__note:hover)::after,
  .kodza-footnote-link.is-ready .kodza-footnote-link__ref:hover + .kodza-footnote-link__note::after,
  .kodza-footnote-link.is-ready .kodza-footnote-link__note:hover::after {
    clip-path: inset(0);
  }

  .kodza-footnote-link.is-ready .kodza-footnote-link__ref:hover + .kodza-footnote-link__note,
  .kodza-footnote-link.is-ready .kodza-footnote-link__note:hover {
    color: var(--kz-footnote-link-ink);
  }
}

@media (prefers-reduced-motion: reduce) {
  .kodza-footnote-link *,
  .kodza-footnote-link *::before,
  .kodza-footnote-link *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}

/* kodza-guard 73c91f13db29 — 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-footnote-link__ref):not(#_) {
  outline: revert;
  outline-offset: revert;
  transition-duration: revert;
}

:where(.kodza-footnote-link p:where(:not([class*="kodza-"]):not(.kodza-footnote-link [class*="kodza-"] *))):not(#_) {
  padding-right: revert;
  transition-duration: revert;
}

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

.kodza-footnote-link:not(#_),
.kodza-footnote-link__tie:not(#_) {
  box-sizing: revert;
}

.kodza-footnote-link__ref:not(#_) {
  text-decoration: revert;
  list-style: revert;
  float: revert;
  box-shadow: revert;
  appearance: revert;
  max-width: revert;
  max-height: revert;
  text-underline-offset: revert;
  text-indent: revert;
  text-shadow: revert;
  transition-property: revert;
  transition-timing-function: revert;
  transition-delay: revert;
  white-space: revert;
  min-height: revert;
}

.kodza-footnote-link p:where(:not([class*="kodza-"]):not(.kodza-footnote-link [class*="kodza-"] *)):not(#_) {
  border: revert;
  border-radius: revert;
  outline: revert;
  text-decoration: revert;
  list-style: revert;
  box-sizing: revert;
  float: revert;
  position: revert;
  padding-top: revert;
  padding-bottom: revert;
  padding-left: 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;
  transition-delay: revert;
}

.kodza-footnote-link p:where(:not([class*="kodza-"]):not(.kodza-footnote-link [class*="kodza-"] *)):not(#_):where(:not([hidden])) {
  display: revert;
}

.kodza-footnote-link p:where(:not([class*="kodza-"]):not(.kodza-footnote-link [class*="kodza-"] *)):not(#_):where([hidden]) {
  display: none;
}

.kodza-footnote-link__ref:not(#_)::before,
.kodza-footnote-link__ref:not(#_)::after {
  box-sizing: 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-footnote-link > p:not(#_) {
  margin: 0 0 1.1em;
}

.kodza-footnote-link > p:last-child:not(#_) {
  margin-bottom: 0;
}

.kodza-footnote-link__ref:not(#_) {
  position: relative;
  top: -0.5em;
  display: inline-block;
  box-sizing: border-box;
  min-width: 1.7em;
  height: 1.6em;
  margin: 0 0.1em 0 0.2em;
  padding: 0 0.45em;
  border: 0;
  border-radius: 999px;
  background: var(--kz-footnote-link-sheet);
  color: var(--kz-footnote-link-muted);
  font: 500 0.62em/1.6em "Geist Mono", ui-monospace, "SF Mono", Menlo, monospace;
  letter-spacing: 0;
  text-align: center;
  text-transform: none;
  vertical-align: baseline;
  cursor: pointer;
  counter-increment: kodza-footnote-link;
  -webkit-tap-highlight-color: transparent;
}

.kodza-footnote-link__ref:not(#_)::before {
  content: "";
  position: absolute;
  inset: -4px;
}

@media (pointer: coarse) {
  .kodza-footnote-link__ref:not(#_)::before {
    inset: -10px -8px;
  }
}

.kodza-footnote-link__ref:focus-visible:not(#_) {
  outline: 2px solid var(--kz-footnote-link-ink);
  outline-offset: 2px;
}

@container kodza-footnote-link (min-width: 760px) {
  .kodza-footnote-link > *:not(#_) {
    padding-right: calc(var(--kz-footnote-link-note-width) + var(--kz-footnote-link-gap));
  }
}

.kodza-footnote-link.is-ready .kodza-footnote-link__ref:not(#_)::after {
  content: attr(data-n);
  background: var(--kz-footnote-link-ink);
  color: var(--kz-footnote-link-paper);
  clip-path: inset(100% 0 0 0);
  pointer-events: none;
  transition: clip-path var(--kz-footnote-link-duration) var(--kz-footnote-link-ease);
}

.kodza-footnote-link.is-ready .kodza-footnote-link__ref:not(#_)::after {
  position: absolute;
  inset: 0;
  border-radius: inherit;
}

.kodza-footnote-link.is-ready .kodza-footnote-link__note:not(#_) {
  transition: color 0.2s ease;
}

.kodza-footnote-link.is-ready .kodza-footnote-link__ref:focus-visible:not(#_)::after,
.kodza-footnote-link.is-ready .kodza-footnote-link__ref.is-active:not(#_)::after,
.kodza-footnote-link.is-ready .kodza-footnote-link__ref[aria-expanded="true"]:not(#_)::after {
  clip-path: inset(0);
}

@media (hover: hover) {
  .kodza-footnote-link.is-ready .kodza-footnote-link__ref:hover:not(#_)::after,
  .kodza-footnote-link.is-ready .kodza-footnote-link__ref:has(+ .kodza-footnote-link__note:hover):not(#_)::after {
    clip-path: inset(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .kodza-footnote-link *:not(#_),
  .kodza-footnote-link *:not(#_)::before,
  .kodza-footnote-link *:not(#_)::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !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 — Footnote Link
// Numbers each note, sets it level with its line in the margin (wide column) or folds it out under
// its line (narrow column, animated height), and turns WordPress or Markdown footnotes into the same.
(() => {
  const SELECTOR = '[data-kodza-footnote-link]';
  const reduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
  const OPEN = { duration: 460, easing: 'cubic-bezier(0.22, 1, 0.36, 1)' };
  const CLOSE = { duration: 380, easing: 'cubic-bezier(0.65, 0, 0.35, 1)' };
  const FOLDED = { height: '0px', paddingTop: '0px', paddingBottom: '0px', marginTop: '0px', marginBottom: '0px', opacity: 0 };
  const BACK_LINK = /^[\s↩︎️]+$/; // a "↩" that leads back to the number, nothing else
  let uid = 0;

  // Footnotes already written: the WordPress Footnotes block, or Markdown (<sup><a href="#fn1">).
  // Each number becomes a button with its note right after it, and the list at the bottom hides.
  function borrow(root, signal) {
    const lists = new Set();
    root.querySelectorAll('sup a[href^="#"]').forEach((link) => {
      const sup = link.closest('sup');
      let item = null;
      try {
        item = document.getElementById(decodeURIComponent(link.getAttribute('href').slice(1)));
      } catch {
        return;
      }
      if (item?.tagName !== 'LI') return;
      const copy = item.cloneNode(true);
      const backs = [link.id, sup.id].filter(Boolean).map((id) => `#${id}`);
      copy.querySelectorAll('a[href]').forEach((a) => {
        if (backs.includes(a.getAttribute('href')) || BACK_LINK.test(a.textContent)) a.remove();
      });
      copy.querySelectorAll('[id]').forEach((el) => el.removeAttribute('id'));
      const body = copy.children.length === 1 && copy.firstElementChild.tagName === 'P' ? copy.firstElementChild : copy;
      const ref = document.createElement('button');
      ref.type = 'button';
      ref.className = 'kodza-footnote-link__ref';
      ref.textContent = link.textContent.replace(/[[\]]/g, '').trim();
      const note = document.createElement('span');
      note.className = 'kodza-footnote-link__note';
      note.innerHTML = body.innerHTML.trim();
      sup.replaceWith(ref, note);
      lists.add(item.closest('.wp-block-footnotes, .footnotes') || item.parentElement);
    });
    lists.forEach((list) => {
      const hidden = list.hidden;
      list.hidden = true;
      signal.addEventListener('abort', () => { list.hidden = hidden; });
    });
  }

  // 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) {
    borrow(root, signal);
    const pairs = [...root.querySelectorAll('.kodza-footnote-link__ref')]
      .map((ref) => ({ ref, note: ref.nextElementSibling, open: false }))
      .filter(({ note }) => note?.classList.contains('kodza-footnote-link__note'));
    if (!pairs.length) return;

    pairs.forEach(({ ref, note }, i) => {
      const n = ref.textContent.trim() || String(i + 1);
      ref.dataset.n = n;
      note.dataset.n = n;
      if (!ref.hasAttribute('aria-label')) ref.setAttribute('aria-label', `Note ${n}`);
      if (!note.id) note.id = `kodza-footnote-link-${++uid}`;
      ref.setAttribute('aria-controls', note.id);
      // A number never starts a line on its own: it is tied to the word before it
      const text = ref.previousSibling;
      if (text?.nodeType !== Node.TEXT_NODE || !/\S$/.test(text.data)) return;
      const at = text.data.search(/\S+$/);
      const word = at > 0 ? text.splitText(at) : text;
      const tie = document.createElement('span');
      tie.className = 'kodza-footnote-link__tie';
      word.before(tie);
      tie.append(word, ref, note);
    });

    // Which layout the CSS picked: the container query floats the notes right in a wide column
    const isWide = () => getComputedStyle(pairs[0].note).float === 'right';
    let wide = null;
    let pinned = null;

    const setPin = (pair) => {
      pinned?.ref.classList.remove('is-active');
      pinned = pair;
      pair?.ref.classList.add('is-active');
    };

    // In the margin, each note's first line sits on the baseline of the line that calls it. A
    // note pushed down by the one above stays where it is: it is never pulled up over it.
    const baseline = () => {
      const probe = document.createElement('span');
      probe.style.cssText = 'display: inline-block; width: 0; height: 0; margin: 0; padding: 0; vertical-align: baseline';
      return probe;
    };
    const align = () => {
      if (!root.offsetWidth) return;
      const scale = root.getBoundingClientRect().width / root.offsetWidth || 1;
      pairs.forEach(({ note }) => {
        note.style.marginTop = '0px';
        const line = baseline();
        const first = baseline();
        note.before(line);
        note.prepend(first);
        const shift = (line.getBoundingClientRect().top - first.getBoundingClientRect().top) / scale;
        line.remove();
        first.remove();
        note.style.marginTop = `${Math.max(0, Math.round(shift * 100) / 100)}px`;
      });
    };

    const settle = (pair) => {
      pair.note.getAnimations().forEach((animation) => animation.cancel());
      pair.note.classList.remove('is-moving');
      pair.note.classList.toggle('is-open', pair.open);
    };

    const layout = () => {
      const now = isWide();
      if (now !== wide) {
        wide = now;
        setPin(null);
        pairs.forEach((pair) => {
          settle(pair);
          if (wide) {
            pair.ref.removeAttribute('aria-expanded');
          } else {
            pair.ref.setAttribute('aria-expanded', String(pair.open));
            pair.note.style.removeProperty('margin-top');
          }
        });
      }
      if (wide) align();
    };

    // Narrow column: the note opens under its line and the text below slides down with it.
    // Stopped half-way, it turns back from where it is.
    const read = (style) => ({
      height: style.height,
      paddingTop: style.paddingTop,
      paddingBottom: style.paddingBottom,
      marginTop: style.marginTop,
      marginBottom: style.marginBottom,
      opacity: style.opacity,
    });
    const toggle = (pair, open) => {
      const { ref, note } = pair;
      if (pair.open === open) return;
      pair.open = open;
      ref.setAttribute('aria-expanded', String(open));
      const moving = note.getAnimations().length > 0 && note.classList.contains('is-moving');
      const from = moving ? read(getComputedStyle(note)) : null;
      note.getAnimations().forEach((animation) => animation.cancel());
      note.classList.add('is-open');
      if (reduceMotion) {
        settle(pair);
        return;
      }
      const full = read(getComputedStyle(note));
      note.classList.add('is-moving');
      const animation = note.animate(
        [from || (open ? FOLDED : full), open ? full : FOLDED],
        { ...(open ? OPEN : CLOSE), fill: open ? 'none' : 'forwards' },
      );
      animation.onfinish = () => settle(pair);
    };

    pairs.forEach((pair) => {
      pair.ref.addEventListener('click', () => {
        if (wide) setPin(pinned === pair ? null : pair);
        else toggle(pair, !pair.open);
      }, { signal });
    });

    root.addEventListener('keydown', (event) => {
      if (event.key !== 'Escape') return;
      if (wide) {
        if (!pinned) return;
        setPin(null);
      } else {
        const pair = pairs.find(({ ref, note }) => ref === event.target || note.contains(event.target));
        if (!pair?.open) return;
        const inside = pair.note.contains(event.target);
        toggle(pair, false);
        if (inside) pair.ref.focus();
      }
      event.preventDefault();
    }, { signal });

    document.addEventListener('pointerdown', (event) => {
      if (pinned && !pinned.ref.contains(event.target) && !pinned.note.contains(event.target)) setPin(null);
    }, { signal });

    // The width decides the layout; anything that moves the lines (fonts, images) moves the notes
    let frame = 0;
    const observer = new ResizeObserver(() => {
      cancelAnimationFrame(frame);
      frame = requestAnimationFrame(layout);
    });
    layout();
    observer.observe(root);
    document.fonts?.ready.then(() => {
      if (!signal.aborted) layout();
    });
    signal.addEventListener('abort', () => {
      observer.disconnect();
      cancelAnimationFrame(frame);
      pairs.forEach(({ note }) => note.getAnimations().forEach((animation) => animation.cancel()));
    });
  }

  // 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.
  const KODZA = Symbol.for('kodza');
  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) => {
    if (root.classList.contains('is-ready')) return; // already running, maybe from another copy of this script
    const controller = new AbortController();
    const saved = { html: written(root), attrs: attrsOf(root), stop: () => destroy(root) };
    instances.set(root, { controller, saved });
    root[KODZA] = saved;
    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);
    // 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[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).
