# Popover

> A panel that grows out of its trigger, arrow pointing back at it, and flips when there is no room. On click, or on hover as a hover card that stays put.

Overlays · popover, hover-card, overlay, share · HTML, CSS, vanilla JS · no dependencies · updated 2026-10-16
Demo: https://kodza.dev/components/popover/

## Files

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

- [`kodza-popover.css`](https://kodza.dev/registry/popover/kodza-popover.css) · 13.5 KB
- [`kodza-popover.js`](https://kodza.dev/registry/popover/kodza-popover.js) · 10.5 KB
- [`kodza-popover.html`](https://kodza.dev/registry/popover/kodza-popover.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-popover.css https://kodza.dev/registry/popover/kodza-popover.css
curl -fsSL --create-dirs -o kodza/kodza-popover.js https://kodza.dev/registry/popover/kodza-popover.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-popover`
- Variables (set them on the root element itself: it declares its own defaults):
  - `--kz-pop-bg: #ffffff`
  - `--kz-pop-fg: #0a0a0a`
  - `--kz-pop-muted: rgba(10, 10, 10, 0.6)`
  - `--kz-pop-line: rgba(10, 10, 10, 0.12)`
  - `--kz-pop-soft: rgba(10, 10, 10, 0.05)`
  - `--kz-pop-ink: #0a0a0a`
  - `--kz-pop-on-ink: #ffffff`
  - `--kz-pop-shadow: 0 18px 40px -16px rgba(10, 10, 10, 0.3)`
  - `--kz-pop-width: 300px`
  - `--kz-pop-ease: cubic-bezier(0.22, 1, 0.36, 1)`
- Modifiers: `.kodza-popover--hover`
- Attributes:
  - `data-side` (e.g. `bottom`, `top`)
- 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 the button (focus in `.kodza-popover:not(.kodza-popover--hover) .kodza-popover__trigger`):
  - `Enter` / `Space`: Opens it with focus inside, or closes it
- On the link (focus in `.kodza-popover--hover .kodza-popover__trigger`):
  - `Tab` / `Shift+Tab`: Closes the card and moves on
- In the panel (focus in `.kodza-popover__panel`):
  - `Escape`: Closes it, focus back on the button
- Anywhere, while it's open (while `.kodza-popover__trigger[aria-expanded="true"]` is on the page):
  - `Escape`: Closes 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-popover {
    --kz-pop-bg: #161616;
    --kz-pop-fg: #f2f2f0;
    --kz-pop-muted: rgba(242, 242, 240, 0.62);
    --kz-pop-line: rgba(255, 255, 255, 0.14);
    --kz-pop-soft: rgba(255, 255, 255, 0.07);
    --kz-pop-ink: #f2f2f0;
    --kz-pop-on-ink: #0a0a0a;
    --kz-pop-shadow: 0 18px 40px -16px rgba(0, 0, 0, 0.8);
  }
}
```

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

Its images have dark versions next to them (`kz-block-1400.webp` → `kz-block-dark-1400.webp`). To swap them on a dark page: `<picture><source media="(prefers-color-scheme: dark)" srcset="…-dark-….webp"><img …></picture>`.

## Use it

### Plain HTML page

- CSS: `kodza/kodza-popover.css` next to the page (the Files commands as they are), linked in `<head>`: `<link rel="stylesheet" href="kodza/kodza-popover.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-popover.js`, loaded with `<script src="kodza/kodza-popover.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-popover.css' -e 'd' -e '}' -e '/^KODZA-JS$/{r kodza/kodza-popover.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">`.
- Images: the artifact blocks every other host, `kodza.dev` included, without an error. Embed each one as a `data:` URI, with a command if you can run one (`curl -s <url> | base64`; the 1400 px files weigh 10 to 30 KB), never by typing base64 out. If you can't run commands, keep the `<img>` with its `width` and `height`, and tell the user the picture stays blank inside the artifact.
- 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.
- Forms: there is nowhere to send them. Handle `submit` in your script with `event.preventDefault()` and show the result in the page.

### 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-popover', $uri . 'kodza-popover.css', [], filemtime($dir . 'kodza-popover.css'));
    wp_enqueue_script('kodza-popover', $uri . 'kodza-popover.js', [], filemtime($dir . 'kodza-popover.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: by default, match the theme's palette. After the component's CSS, point these variables at the theme's colours, on the component root, Kodza's value as the fallback:
  `.kodza-popover { --kz-pop-fg: var(TEXT, #0a0a0a); --kz-pop-bg: var(BACKGROUND, #ffffff); --kz-pop-ink: var(ACCENT, #0a0a0a); --kz-pop-on-ink: var(BACKGROUND, #ffffff); }`
  TEXT, BACKGROUND and ACCENT (the colour the theme fills its own buttons with) are the theme's own colour variables — block themes (theme.json, like Twenty Twenty-Five): `--wp--preset--color--contrast`, `--wp--preset--color--base`, `--wp--preset--color--contrast` (they fill their buttons with it; their accent-1… colours are decorative); Astra: `--ast-global-color-2`, `--ast-global-color-4`, `--ast-global-color-0`; Kadence: `--global-palette3`, `--global-palette9`, `--global-palette1`; GeneratePress: `--contrast`, `--base-3`, `--accent`; Blocksy: `--theme-palette-color-4`, `--theme-palette-color-8`, `--theme-palette-color-1`. Use only these names, and only if the site really has them (the theme's CSS, or Styles → Colors): the `--wp--preset--color--black`, `--white`, `--vivid-…` that WordPress adds everywhere are not the theme's palette. Another theme, or one without these variables (Hello Elementor, OceanWP): leave the variables alone, it keeps Kodza's monochrome; same when the developer asks for monochrome or the Kodza look. Leave the translucent greys (`rgba(10, 10, 10, …)`) as they are: they suit any light background. On a dark palette, set the other variables from Dark mode too.
- 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-popover.css` and `assets/kodza-popover.js` (the Files commands with `-o assets/…`).
- In the section: `{{ 'kodza-popover.css' | asset_url | stylesheet_tag }}` and `<script src="{{ 'kodza-popover.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/`): `Popover.tsx` (below), the CSS block under Code saved as `popover.css` and the JS block as `popover.js`, both as they are. The HTML block is already inside the component: skip it.
- Use it: `import { Popover } from '@/components/kodza/Popover';` then `<Popover />`. Props: `variant` ("hover", or several in an array), `vars` (the `--kz-…` variables listed under API, e.g. `vars={{ '--kz-pop-bg': … }}`), `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 './popover.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.

```tsx
'use client';
// Kodza — Popover, for React. From https://kodza.dev/components/popover/
// 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: popover.css and popover.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.
import { useRef, useEffect, type ComponentPropsWithoutRef, type ComponentRef, type CSSProperties } from 'react';
import './popover.css';

type Variant = "hover";

export type PopoverProps = Omit<ComponentPropsWithoutRef<'div'>, "children" | "variant" | "vars"> & {
  /** Modifier class(es): .kodza-popover--hover */
  variant?: Variant | Variant[];
  /** Settings, as CSS variables on the root */
  vars?: {
    /** default: #ffffff */
    "--kz-pop-bg"?: string | number;
    /** default: #0a0a0a */
    "--kz-pop-fg"?: string | number;
    /** default: rgba(10, 10, 10, 0.6) */
    "--kz-pop-muted"?: string | number;
    /** default: rgba(10, 10, 10, 0.12) */
    "--kz-pop-line"?: string | number;
    /** default: rgba(10, 10, 10, 0.05) */
    "--kz-pop-soft"?: string | number;
    /** default: #0a0a0a */
    "--kz-pop-ink"?: string | number;
    /** default: #ffffff */
    "--kz-pop-on-ink"?: string | number;
    /** default: 0 18px 40px -16px rgba(10, 10, 10, 0.3) */
    "--kz-pop-shadow"?: string | number;
    /** default: 300px */
    "--kz-pop-width"?: string | number;
    /** default: cubic-bezier(0.22, 1, 0.36, 1) */
    "--kz-pop-ease"?: string | number;
  };
  className?: string;
};

export function Popover({ variant, vars, className, style, ...rest }: PopoverProps) {
  const ref = useRef<ComponentRef<'div'>>(null);
  const classes = ["kodza-popover", ...([] as string[]).concat(variant ?? []).map((v) => `kodza-popover--${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('./popover.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} style={{ ...vars, ...style } as CSSProperties} ref={ref}>
      <button className="kodza-popover__trigger" type="button">Share</button>
      <div className="kodza-popover__panel" popover="">
        <p className="kodza-popover__title">Share this component</p>
        <p className="kodza-popover__text">Anyone with the link can copy it. That is the whole point.</p>
        <div className="kodza-popover__row">
          <input className="kodza-popover__field" type="text" defaultValue="kodza.dev/c/fill-button" readOnly aria-label="Link" />
          {' '}
          <button className="kodza-popover__copy" type="button">
            <span className="kodza-popover__copy-words">
              <span>Copy</span>
              <span aria-hidden="true">Copied</span>
            </span>
          </button>
        </div>
      </div>
    </div>
  );
}
```

## Code

```html
<div class="kodza-popover">
  <button class="kodza-popover__trigger" type="button">Share</button>
  <div class="kodza-popover__panel" popover>
    <p class="kodza-popover__title">Share this component</p>
    <p class="kodza-popover__text">Anyone with the link can copy it. That is the whole point.</p>
    <div class="kodza-popover__row">
      <input class="kodza-popover__field" type="text" value="kodza.dev/c/fill-button" readonly aria-label="Link">
      <button class="kodza-popover__copy" type="button"><span class="kodza-popover__copy-words"><span>Copy</span><span aria-hidden="true">Copied</span></span></button>
    </div>
  </div>
</div>

<p class="kodza-popover kodza-popover--hover">
  Start with the
  <a class="kodza-popover__trigger" href="#">Fill Button</a>,
  everyone does.
  <span class="kodza-popover__panel" popover>
    <img class="kodza-popover__image" src="https://kodza.dev/media/kz-block-1400.webp" alt="">
    <span class="kodza-popover__title">Fill Button</span>
    <span class="kodza-popover__meta">Buttons · 3 KB · 0 dependencies</span>
    <span class="kodza-popover__text">The ink follows your cursor in, and leaves the way it came.</span>
  </span>
</p>
```

```css
/* Kodza License: free to use, client work included. Not to resell or redistribute, ported or not: https://kodza.dev/docs/#print-license */
/* Kodza — Popover
   A panel attached to its trigger, on the native Popover API (top layer, closes on Escape and
   on a click elsewhere). It grows out of the trigger, its arrow pointing back at it, flips
   above when there is no room below and stays inside the screen. With --hover it opens on
   hover or focus after a short wait, as a hover card, and stays while the pointer is on it.
   Everything is tuned with the --kz-pop-* variables. */
.kodza-popover {
  --kz-pop-bg: #ffffff;
  --kz-pop-fg: #0a0a0a;
  --kz-pop-muted: rgba(10, 10, 10, 0.6);
  --kz-pop-line: rgba(10, 10, 10, 0.12);
  --kz-pop-soft: rgba(10, 10, 10, 0.05);
  --kz-pop-ink: #0a0a0a;
  --kz-pop-on-ink: #ffffff;
  --kz-pop-shadow: 0 18px 40px -16px rgba(10, 10, 10, 0.3);
  --kz-pop-width: 300px;
  --kz-pop-ease: cubic-bezier(0.22, 1, 0.36, 1);

  color: var(--kz-pop-fg);
}

.kodza-popover:not(.kodza-popover--hover) {
  display: inline-block;
}

.kodza-popover--hover {
  margin: 0;
  font-size: 17px;
  line-height: 1.6;
}

button.kodza-popover__trigger {
  height: 44px;
  padding: 0 20px;
  border: 0;
  border-radius: 999px;
  background: var(--kz-pop-bg);
  box-shadow: inset 0 0 0 1px var(--kz-pop-line);
  color: inherit;
  font: inherit;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: box-shadow 0.25s ease;
}

button.kodza-popover__trigger:hover,
button.kodza-popover__trigger[aria-expanded="true"] {
  box-shadow: inset 0 0 0 1px var(--kz-pop-muted);
}

a.kodza-popover__trigger {
  border-radius: 4px;
  color: inherit;
  font-weight: 500;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 4px;
}

.kodza-popover__trigger:focus-visible,
.kodza-popover__copy:focus-visible {
  outline: 2px solid var(--kz-pop-fg);
  outline-offset: 3px;
}

/* The panel: placed by the script, grows out of the trigger */
.kodza-popover__panel {
  position: fixed;
  inset: auto;
  top: var(--kz-pop-y, 0);
  left: var(--kz-pop-x, 0);
  width: var(--kz-pop-width);
  max-width: calc(100vw - 16px);
  margin: 0;
  padding: 18px;
  overflow: visible;
  border: 0;
  border-radius: 16px;
  background: var(--kz-pop-bg);
  box-shadow: 0 0 0 1px var(--kz-pop-line), var(--kz-pop-shadow);
  color: var(--kz-pop-fg);
  font: inherit;
  font-size: 15px;
  line-height: 1.5;
  text-align: left;
  box-sizing: border-box;
}

.kodza-popover__panel:popover-open,
.kodza-popover__panel.is-open {
  display: grid;
  gap: 8px;
}

/* The arrow, pointing at the trigger */
.kodza-popover__panel::before {
  content: "";
  position: absolute;
  left: var(--kz-pop-arrow, 50%);
  width: 12px;
  height: 12px;
  border-radius: 2px;
  background: var(--kz-pop-bg);
  box-shadow: -1px -1px 0 0 var(--kz-pop-line);
  transform: translate(-50%, -50%) rotate(45deg);
}

.kodza-popover__panel[data-side="bottom"]::before {
  top: 0;
}

.kodza-popover__panel[data-side="top"]::before {
  top: 100%;
  box-shadow: 1px 1px 0 0 var(--kz-pop-line);
}

.kodza-popover__title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.kodza-popover__text {
  margin: 0;
  font-size: 14px;
  color: var(--kz-pop-muted);
  text-wrap: pretty;
}

.kodza-popover__meta {
  margin-top: -6px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 11px;
  color: var(--kz-pop-muted);
}

.kodza-popover__image {
  width: 100%;
  height: 120px;
  margin-bottom: 4px;
  border-radius: 10px;
  object-fit: cover;
}

.kodza-popover__row {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}

.kodza-popover__field {
  flex: 1;
  box-sizing: border-box;
  min-width: 0;
  height: 38px;
  padding: 0 10px;
  border: 0;
  border-radius: 10px;
  background: var(--kz-pop-soft);
  color: inherit;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px;
  outline: none;
}

.kodza-popover__field:focus-visible {
  box-shadow: inset 0 0 0 1.5px var(--kz-pop-fg);
}

.kodza-popover__copy {
  height: 38px;
  padding: 0 12px;
  border: 0;
  border-radius: 10px;
  background: var(--kz-pop-ink);
  color: var(--kz-pop-on-ink);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

/* "Copy" rolls to "Copied". Both words share one grid cell, so the button keeps the width
   of the longer one and the field next to it never moves */
.kodza-popover__copy-words {
  display: inline-grid;
  justify-items: center;
  overflow: hidden;
  vertical-align: top;
}

.kodza-popover__copy-words > span {
  grid-area: 1 / 1;
}

/* The word waiting its turn, under the button */
.kodza-popover__copy-words > [aria-hidden="true"] {
  transform: translateY(110%);
}

@media (prefers-reduced-motion: reduce) {
  button.kodza-popover__trigger {
    transition-duration: 0.01ms !important;
  }
}

/* Theming example — on a dark background:
.dark-section .kodza-popover {
  --kz-pop-bg: #161616;
  --kz-pop-fg: #f2f2f0;
  --kz-pop-muted: rgba(242, 242, 240, 0.62);
  --kz-pop-line: rgba(255, 255, 255, 0.14);
  --kz-pop-soft: rgba(255, 255, 255, 0.07);
  --kz-pop-ink: #f2f2f0;
  --kz-pop-on-ink: #0a0a0a;
  --kz-pop-shadow: 0 18px 40px -16px rgba(0, 0, 0, 0.8);
}
*/

/* kodza-guard 4308736b50ab — 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-popover):not(#_) {
  font-size: revert;
  line-height: revert;
}

:where(.kodza-popover__trigger):not(#_) {
  border: revert;
  padding: revert;
  outline: revert;
  text-decoration: revert;
  transition: revert;
  background-color: revert;
  background-image: revert;
  box-shadow: revert;
  outline-offset: revert;
  font-family: revert;
  font-size: revert;
  font-style: revert;
  line-height: revert;
  text-underline-offset: revert;
}

:where(.kodza-popover__field):not(#_) {
  box-shadow: revert;
}

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

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

.kodza-popover:not(#_) {
  border: revert;
  padding: revert;
  border-radius: revert;
  outline: revert;
  text-decoration: revert;
  transition: revert;
  list-style: revert;
  box-sizing: revert;
  position: revert;
  background-color: revert;
  background-image: revert;
  box-shadow: revert;
  outline-offset: revert;
  appearance: revert;
  max-height: revert;
  font-family: revert;
  font-weight: revert;
  font-style: revert;
  letter-spacing: revert;
  text-transform: revert;
  text-underline-offset: revert;
  text-align: revert;
  text-indent: revert;
  text-shadow: revert;
  vertical-align: revert;
}

.kodza-popover__trigger:not(#_) {
  margin: revert;
  list-style: revert;
  box-sizing: revert;
  float: revert;
  position: revert;
  appearance: revert;
  max-width: revert;
  max-height: revert;
  letter-spacing: revert;
  text-transform: revert;
  text-align: revert;
  text-indent: revert;
  text-shadow: revert;
  vertical-align: revert;
  white-space: revert;
  min-height: revert;
}

.kodza-popover__title:not(#_) {
  border: 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-width: revert;
  max-height: revert;
  color: revert;
  font-family: 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;
}

.kodza-popover__text:not(#_) {
  border: 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-width: revert;
  max-height: revert;
  font-family: 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;
}

.kodza-popover__row:not(#_),
.kodza-popover__copy-words:not(#_),
.kodza-popover__meta:not(#_),
.kodza-popover__copy-words span:where(:not([class*="kodza-"])):not(#_) {
  box-sizing: revert;
}

.kodza-popover__field:not(#_) {
  margin: revert;
  text-decoration: revert;
  transition: revert;
  list-style: revert;
  float: revert;
  position: revert;
  outline-offset: revert;
  appearance: revert;
  max-width: revert;
  max-height: 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;
  white-space: revert;
  min-height: revert;
}

.kodza-popover__copy:not(#_) {
  margin: revert;
  text-decoration: revert;
  transition: revert;
  list-style: revert;
  box-sizing: revert;
  float: revert;
  position: revert;
  box-shadow: revert;
  appearance: revert;
  max-width: 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-popover__image:not(#_) {
  border: revert;
  padding: revert;
  outline: revert;
  text-decoration: revert;
  transition: revert;
  list-style: revert;
  box-sizing: revert;
  float: revert;
  position: revert;
  margin-top: revert;
  margin-right: revert;
  margin-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;
}

.kodza-popover__trigger:not(#_):where(:not([hidden])),
.kodza-popover__title:not(#_):where(:not([hidden])),
.kodza-popover__text:not(#_):where(:not([hidden])),
.kodza-popover__field:not(#_):where(:not([hidden])),
.kodza-popover__copy:not(#_):where(:not([hidden])),
.kodza-popover__image:not(#_):where(:not([hidden])) {
  display: revert;
}

.kodza-popover__trigger:not(#_):where([hidden]),
.kodza-popover__title:not(#_):where([hidden]),
.kodza-popover__text:not(#_):where([hidden]),
.kodza-popover__field:not(#_):where([hidden]),
.kodza-popover__copy:not(#_):where([hidden]),
.kodza-popover__image:not(#_):where([hidden]) {
  display: none;
}

.kodza-popover__panel:not(#_)::before {
  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-popover:where(p):not(#_) {
  color: var(--kz-pop-fg);
}

.kodza-popover:not(.kodza-popover--hover):where(p):not(#_) {
  display: inline-block;
}

.kodza-popover--hover:not(#_) {
  font-size: 17px;
  line-height: 1.6;
}

button.kodza-popover__trigger:not(#_) {
  height: 44px;
  padding: 0 20px;
  border: 0;
  border-radius: 999px;
  background: var(--kz-pop-bg);
  box-shadow: inset 0 0 0 1px var(--kz-pop-line);
  color: inherit;
  font: inherit;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: box-shadow 0.25s ease;
}

button.kodza-popover__trigger:hover:not(#_),
button.kodza-popover__trigger[aria-expanded="true"]:not(#_) {
  box-shadow: inset 0 0 0 1px var(--kz-pop-muted);
}

a.kodza-popover__trigger:not(#_) {
  border-radius: 4px;
  color: inherit;
  font-weight: 500;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 4px;
}

.kodza-popover__trigger:focus-visible:not(#_),
.kodza-popover__copy:focus-visible:not(#_) {
  outline: 2px solid var(--kz-pop-fg);
  outline-offset: 3px;
}

.kodza-popover__title:where(p):not(#_) {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.kodza-popover__text:where(p):not(#_) {
  margin: 0;
  font-size: 14px;
  color: var(--kz-pop-muted);
}

.kodza-popover__image:not(#_) {
  margin-bottom: 4px;
  border-radius: 10px;
}

.kodza-popover__field:not(#_) {
  flex: 1;
  box-sizing: border-box;
  min-width: 0;
  height: 38px;
  padding: 0 10px;
  border: 0;
  border-radius: 10px;
  background: var(--kz-pop-soft);
  color: inherit;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px;
  outline: none;
}

.kodza-popover__field:focus-visible:not(#_) {
  box-shadow: inset 0 0 0 1.5px var(--kz-pop-fg);
}

.kodza-popover__copy:not(#_) {
  height: 38px;
  padding: 0 12px;
  border: 0;
  border-radius: 10px;
  background: var(--kz-pop-ink);
  color: var(--kz-pop-on-ink);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

@media (prefers-reduced-motion: reduce) {
  button.kodza-popover__trigger:not(#_) {
    transition-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 — Popover
// Places the panel under its trigger (above when there is no room), keeps it on screen with
// the arrow still on the trigger, and plays the entrance and the exit from the trigger. Click
// to open; with --hover, hover or focus (after 350 ms), and it stays while the pointer is on it.
// The native Popover API handles clicks elsewhere; the trigger and Escape close it with its exit.
// A fallback covers older browsers.
(() => {
  const SELECTOR = '.kodza-popover';
  const reduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
  const native = typeof HTMLElement.prototype.showPopover === 'function';
  const ease = 'cubic-bezier(0.22, 1, 0.36, 1)';
  let uid = 0;

  // One instance. Everything it starts is tied to `signal`, so kodza:destroy stops it all
  function mount(root, signal) {
    const trigger = root.querySelector('.kodza-popover__trigger');
    const panel = root.querySelector('.kodza-popover__panel');
    if (!trigger || !panel) return;
    const hover = root.classList.contains('kodza-popover--hover');
    panel.id = `kodza-popover-${++uid}`;
    trigger.setAttribute('aria-controls', panel.id);
    trigger.setAttribute('aria-expanded', 'false');
    if (hover) trigger.setAttribute('aria-describedby', panel.id);
    else {
      panel.setAttribute('role', 'dialog');
      const title = panel.querySelector('.kodza-popover__title');
      if (title) panel.setAttribute('aria-labelledby', (title.id = `${panel.id}-title`));
    }
    if (!native) panel.removeAttribute('popover');

    const isOpen = () => (native ? panel.matches(':popover-open') : panel.classList.contains('is-open'));

    // Under the trigger, or above; centred on it but kept 8 px inside the screen
    const place = () => {
      const t = trigger.getBoundingClientRect();
      const w = panel.offsetWidth;
      const h = panel.offsetHeight;
      const below = t.bottom + 12 + h <= innerHeight - 8 || t.top - 12 - h < 8;
      const x = Math.min(innerWidth - 8 - w, Math.max(8, t.left + t.width / 2 - w / 2));
      const y = below ? t.bottom + 12 : t.top - 12 - h;
      panel.dataset.side = below ? 'bottom' : 'top';
      panel.style.setProperty('--kz-pop-x', `${x}px`);
      panel.style.setProperty('--kz-pop-y', `${y}px`);
      panel.style.setProperty('--kz-pop-arrow', `${t.left + t.width / 2 - x}px`);
      // It grows out of the arrow
      panel.style.transformOrigin = `${t.left + t.width / 2 - x}px ${below ? 0 : h}px`;
      return below;
    };

    // The copy button: copies the field, and its word rolls to "Copied". Both words sit in the
    // same grid cell (the button keeps the width of the longer one), the hidden one waits below
    const copy = panel.querySelector('.kodza-popover__copy');
    const field = panel.querySelector('.kodza-popover__field');
    const words = copy ? [...copy.querySelectorAll('.kodza-popover__copy-words > span')] : [];
    let restCopy = () => {};
    if (copy && field && words.length === 2) {
      const [idle, done] = words;
      let timer = 0;
      // The shown word leaves upwards, the next one comes up from below
      const roll = (next) => {
        const prev = next === done ? idle : done;
        if (!next.hasAttribute('aria-hidden')) return;
        prev.setAttribute('aria-hidden', 'true');
        next.removeAttribute('aria-hidden');
        if (reduceMotion) return;
        const timing = { duration: 320, easing: ease };
        prev.animate([{ transform: 'none' }, { transform: 'translateY(-110%)' }], timing);
        next.animate([{ transform: 'translateY(110%)' }, { transform: 'none' }], timing);
      };
      // Closed: back to "Copy" at once, out of sight
      restCopy = () => {
        clearTimeout(timer);
        words.forEach((word) => word.getAnimations().forEach((animation) => animation.cancel()));
        idle.removeAttribute('aria-hidden');
        done.setAttribute('aria-hidden', 'true');
      };
      copy.addEventListener('click', async () => {
        try {
          await navigator.clipboard.writeText(field.value);
        } catch {
          field.select();
        }
        roll(done);
        clearTimeout(timer);
        timer = setTimeout(() => roll(idle), 1600);
      }, { signal });
      signal.addEventListener('abort', () => clearTimeout(timer));
    }

    let leaving = null;
    // Where the panel is right now, mid-animation included: a change of mind starts from there
    const now = () => {
      const { opacity, transform } = getComputedStyle(panel);
      panel.getAnimations().forEach((animation) => animation.cancel());
      return { opacity, transform };
    };
    const show = () => {
      if (isOpen() && !leaving) return;
      // Called back while it leaves: it comes back from where it is
      if (isOpen()) {
        leaving = null;
        trigger.setAttribute('aria-expanded', 'true');
        return panel.animate([now(), { opacity: 1, transform: 'none' }], { duration: 240, easing: ease });
      }
      leaving?.cancel();
      leaving = null;
      if (native) panel.showPopover();
      else panel.classList.add('is-open');
      const below = place();
      trigger.setAttribute('aria-expanded', 'true');
      if (!reduceMotion) panel.animate([{ opacity: 0, transform: `translateY(${below ? -6 : 6}px) scale(0.92)` }, { opacity: 1, transform: 'none' }], { duration: 320, easing: ease });
    };
    const hide = (refocus = false) => {
      if (!isOpen() || leaving) return;
      trigger.setAttribute('aria-expanded', 'false');
      const done = () => {
        if (native) return panel.hidePopover();
        panel.classList.remove('is-open');
        restCopy();
      };
      if (refocus) trigger.focus({ preventScroll: true });
      if (reduceMotion) return done();
      const below = panel.dataset.side !== 'top';
      leaving = panel.animate([now(), { opacity: 0, transform: `translateY(${below ? -4 : 4}px) scale(0.96)` }], { duration: 160, easing: 'ease-in', fill: 'forwards' });
      leaving.finished.then(() => {
        leaving = null;
        done();
        panel.getAnimations().forEach((animation) => animation.cancel());
      }).catch(() => {});
    };

    // The native popover closed (a click elsewhere, or the script): keep the trigger in step,
    // and the copy button back at rest
    panel.addEventListener('toggle', (event) => {
      if (event.newState !== 'closed') return;
      trigger.setAttribute('aria-expanded', 'false');
      restCopy();
    }, { signal });

    if (hover) {
      let timer = 0;
      const soon = (fn, ms) => {
        clearTimeout(timer);
        timer = setTimeout(fn, ms);
      };
      [trigger, panel].forEach((el) => {
        el.addEventListener('pointerenter', () => soon(show, isOpen() ? 0 : 350), { signal });
        el.addEventListener('pointerleave', () => soon(() => hide(), 200), { signal });
      });
      trigger.addEventListener('focus', () => soon(show, 350), { signal });
      trigger.addEventListener('blur', () => soon(() => hide(), 100), { signal });
      signal.addEventListener('abort', () => clearTimeout(timer));
    } else {
      // The trigger is the panel's invoker (popovertarget): a press on it no longer
      // light-dismisses the panel at once, the click closes it with its exit. A browser that
      // still dismisses it on the press has closed it already: the click must not reopen it
      if (native && trigger.localName === 'button') trigger.setAttribute('popovertarget', panel.id);
      let closedByPress = false;
      trigger.addEventListener('pointerdown', () => (closedByPress = isOpen() && !leaving), { signal });
      trigger.addEventListener('click', (event) => {
        event.preventDefault(); // the script opens and closes it, not popovertarget
        const pressed = closedByPress;
        closedByPress = false;
        if (leaving) return show(); // clicked again while it leaves: it comes back
        if (pressed || isOpen()) return hide();
        show();
        // From the keyboard, the focus goes into the panel
        if (trigger.matches(':focus-visible')) panel.querySelector('button, input, a[href]')?.focus();
      }, { signal });
      if (!native) document.addEventListener('pointerdown', (event) => !root.contains(event.target) && hide(), { signal });
    }

    // Escape, from the panel or its trigger: the exit plays (the native close would cut it)
    root.addEventListener('keydown', (event) => {
      if (event.key !== 'Escape' || !isOpen()) return;
      event.preventDefault();
      hide(!hover);
    }, { signal });

    addEventListener('resize', () => isOpen() && place(), { signal });
    addEventListener('scroll', () => isOpen() && place(), { passive: true, signal });

    // Stopped while open (or leaving): the popover leaves the top layer at once
    signal.addEventListener('abort', () => {
      leaving?.cancel();
      if (native && panel.matches(':popover-open')) panel.hidePopover();
    });
  }

  // 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.
  const instances = new WeakMap();
  const find = (scope = document) => [scope, ...scope.querySelectorAll(SELECTOR)].filter((el) => el.matches?.(SELECTOR));
  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();
    instances.set(root, { controller, html: root.innerHTML, attrs: [...root.attributes].map((a) => [a.name, a.value]) });
    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.controller.abort();
    [...root.attributes].forEach((a) => root.removeAttribute(a.name));
    instance.attrs.forEach(([name, value]) => root.setAttribute(name, value));
    root.innerHTML = instance.html;
  });
  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).
