# Search Autocomplete

> A search field over a real datalist: suggestions unroll under it, grouped, with the letters you typed underlined. "/" jumps in, arrows and Enter drive.

Forms · search, autocomplete, combobox, form · HTML, CSS, vanilla JS · no dependencies · updated 2026-10-21
Demo: https://kodza.dev/components/search-input/

## Files

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

- [`kodza-search-input.css`](https://kodza.dev/registry/search-input/kodza-search-input.css) · 14.5 KB
- [`kodza-search-input.js`](https://kodza.dev/registry/search-input/kodza-search-input.js) · 12.1 KB
- [`kodza-search-input.html`](https://kodza.dev/registry/search-input/kodza-search-input.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-search-input.css https://kodza.dev/registry/search-input/kodza-search-input.css
curl -fsSL --create-dirs -o kodza/kodza-search-input.js https://kodza.dev/registry/search-input/kodza-search-input.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-search`
- Variables (set them on the root element itself: it declares its own defaults):
  - `--kz-search-bg: #ffffff`
  - `--kz-search-fg: #0a0a0a`
  - `--kz-search-muted: rgba(10, 10, 10, 0.6)`
  - `--kz-search-line: rgba(10, 10, 10, 0.14)`
  - `--kz-search-line-hover: rgba(10, 10, 10, 0.3)`
  - `--kz-search-soft: rgba(10, 10, 10, 0.06)`
  - `--kz-search-shadow: 0 18px 40px -16px rgba(10, 10, 10, 0.3)`
  - `--kz-search-height: 48px`
  - `--kz-search-ease: cubic-bezier(0.22, 1, 0.36, 1)`
  - `--kz-search-mono: ui-monospace, "SF Mono", Menlo, monospace`
- Events: `kodza:search` (bubbling, from the root)
- Hooks on the root element: `root.kodzaSearch` (see the comment at the top of the JS)
- 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.

- In the field, while suggestions are open (focus in `.kodza-search__input`, while `.kodza-search.is-open` is on the page):
  - `ArrowDown` / `ArrowUp`: Next or previous suggestion, round and round
  - `Enter`: Picks the highlighted suggestion
  - `Tab`: Closes the suggestions and moves on
- In the field (focus in `.kodza-search__input`):
  - `ArrowDown` / `ArrowUp`: Opens the suggestions
  - a letter: Filters the suggestions, letters in order
  - `Escape`: Closes the suggestions and clears the text, in two presses
- Anywhere outside a text field:
  - `/`: Jumps to the search field

## 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-search {
    --kz-search-bg: #161616;
    --kz-search-fg: #f2f2f0;
    --kz-search-muted: rgba(242, 242, 240, 0.62);
    --kz-search-line: rgba(255, 255, 255, 0.14);
    --kz-search-line-hover: rgba(255, 255, 255, 0.3);
    --kz-search-soft: rgba(255, 255, 255, 0.08);
    --kz-search-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-search { … }`); a single dark section, under that section's class.

## Use it

### Plain HTML page

- CSS: `kodza/kodza-search-input.css` next to the page (the Files commands as they are), linked in `<head>`: `<link rel="stylesheet" href="kodza/kodza-search-input.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-search-input.js`, loaded with `<script src="kodza/kodza-search-input.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-search-input.css' -e 'd' -e '}' -e '/^KODZA-JS$/{r kodza/kodza-search-input.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.
- 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.
- 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-search-input', $uri . 'kodza-search-input.css', [], filemtime($dir . 'kodza-search-input.css'));
    wp_enqueue_script('kodza-search-input', $uri . 'kodza-search-input.js', [], filemtime($dir . 'kodza-search-input.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-search { --kz-search-fg: var(TEXT, #0a0a0a); --kz-search-bg: 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-search-input.css` and `assets/kodza-search-input.js` (the Files commands with `-o assets/…`).
- In the section: `{{ 'kodza-search-input.css' | asset_url | stylesheet_tag }}` and `<script src="{{ 'kodza-search-input.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/`): `SearchAutocomplete.tsx` (below), the CSS block under Code saved as `search-input.css` and the JS block as `search-input.js`, both as they are. The HTML block is already inside the component: skip it.
- Use it: `import { SearchAutocomplete } from '@/components/kodza/SearchAutocomplete';` then `<SearchAutocomplete>/</SearchAutocomplete>`. Props: `vars` (the `--kz-…` variables listed under API, e.g. `vars={{ '--kz-search-bg': … }}`), `children` (the text, plain), `onSearch` (the `kodza:search` event), `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 './search-input.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 — Search Autocomplete, for React. From https://kodza.dev/components/search-input/
// 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: search-input.css and search-input.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 './search-input.css';

export type SearchAutocompleteProps = Omit<ComponentPropsWithoutRef<'div'>, "children" | "vars" | "onSearch"> & {
  /** Settings, as CSS variables on the root */
  vars?: {
    /** default: #ffffff */
    "--kz-search-bg"?: string | number;
    /** default: #0a0a0a */
    "--kz-search-fg"?: string | number;
    /** default: rgba(10, 10, 10, 0.6) */
    "--kz-search-muted"?: string | number;
    /** default: rgba(10, 10, 10, 0.14) */
    "--kz-search-line"?: string | number;
    /** default: rgba(10, 10, 10, 0.3) */
    "--kz-search-line-hover"?: string | number;
    /** default: rgba(10, 10, 10, 0.06) */
    "--kz-search-soft"?: string | number;
    /** default: 0 18px 40px -16px rgba(10, 10, 10, 0.3) */
    "--kz-search-shadow"?: string | number;
    /** default: 48px */
    "--kz-search-height"?: string | number;
    /** default: cubic-bezier(0.22, 1, 0.36, 1) */
    "--kz-search-ease"?: string | number;
    /** default: ui-monospace, "SF Mono", Menlo, monospace */
    "--kz-search-mono"?: string | number;
  };
  /** The text, plain: the script reads it and rebuilds the markup around it */
  children?: string;
  /** "kodza:search", fired by the script (bubbles from the root) */
  onSearch?: (event: CustomEvent) => void;
  className?: string;
};

export function SearchAutocomplete({ vars, children = "/", onSearch, className, style, ...rest }: SearchAutocompleteProps) {
  const ref = useRef<ComponentRef<'div'>>(null);
  const classes = ["kodza-search", 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, children, 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('./search-input.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 || !onSearch) return;
    const listener = (event: Event) => onSearch(event as CustomEvent);
    root.addEventListener("kodza:search", listener);
    return () => root.removeEventListener("kodza:search", listener);
  }, [onSearch, key]);

  return (
    <div key={key} {...rest} className={classes} style={{ ...vars, ...style } as CSSProperties} ref={ref}>
      <label className="kodza-search__box">
        <svg className="kodza-search__icon" viewBox="0 0 16 16" aria-hidden="true">
          <circle cx="7" cy="7" r="4.5" />
          <path d="m10.5 10.5 3 3" />
        </svg>
        {' '}
        <input className="kodza-search__input" type="search" name="q" placeholder="Search components" list="kodza-search-list" autoComplete="off" aria-label="Search components" />
        {' '}
        <kbd className="kodza-search__key">{children}</kbd>
      </label>
      {' '}
      <datalist className="kodza-search__options" id="kodza-search-list">
        <option value="Fill Button" label="Buttons" />
        <option value="Arrow Button" label="Buttons" />
        <option value="Scramble Link" label="Links" />
        <option value="Text Shimmer" label="Text" />
        <option value="Typewriter" label="Text" />
        <option value="Image Gallery" label="Images" />
        <option value="Pricing Plans" label="Cards" />
        <option value="Sticky Cards" label="Cards" />
        <option value="Command Palette" label="Navigation" />
        <option value="Scroll Header" label="Navigation" />
        <option value="Date Picker" label="Forms" />
        <option value="Multi Select" label="Forms" />
      </datalist>
    </div>
  );
}
```

## Code

```html
<div class="kodza-search">
  <label class="kodza-search__box">
    <svg class="kodza-search__icon" viewBox="0 0 16 16" aria-hidden="true"><circle cx="7" cy="7" r="4.5"/><path d="m10.5 10.5 3 3"/></svg>
    <input class="kodza-search__input" type="search" name="q" placeholder="Search components" list="kodza-search-list" autocomplete="off" aria-label="Search components">
    <kbd class="kodza-search__key">/</kbd>
  </label>
  <datalist class="kodza-search__options" id="kodza-search-list">
    <option value="Fill Button" label="Buttons"></option>
    <option value="Arrow Button" label="Buttons"></option>
    <option value="Scramble Link" label="Links"></option>
    <option value="Text Shimmer" label="Text"></option>
    <option value="Typewriter" label="Text"></option>
    <option value="Image Gallery" label="Images"></option>
    <option value="Pricing Plans" label="Cards"></option>
    <option value="Sticky Cards" label="Cards"></option>
    <option value="Command Palette" label="Navigation"></option>
    <option value="Scroll Header" label="Navigation"></option>
    <option value="Date Picker" label="Forms"></option>
    <option value="Multi Select" label="Forms"></option>
  </datalist>
</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 — Search Autocomplete
   A search field over a real datalist (so the browser's own suggestions work without JS).
   With the script: suggestions unroll under the field, grouped, the letters you typed are
   underlined, a highlight slides between them and the list eases to its new height as you
   type. "/" jumps into the field from anywhere. Plug your own source with
   root.kodzaSearch = async (query) => [{ label, meta }].
   Everything is tuned with the --kz-search-* variables. */
.kodza-search {
  --kz-search-bg: #ffffff;
  --kz-search-fg: #0a0a0a;
  --kz-search-muted: rgba(10, 10, 10, 0.6);
  --kz-search-line: rgba(10, 10, 10, 0.14);
  --kz-search-line-hover: rgba(10, 10, 10, 0.3);
  --kz-search-soft: rgba(10, 10, 10, 0.06);
  --kz-search-shadow: 0 18px 40px -16px rgba(10, 10, 10, 0.3);
  --kz-search-height: 48px;
  --kz-search-ease: cubic-bezier(0.22, 1, 0.36, 1);
  --kz-search-mono: ui-monospace, "SF Mono", Menlo, monospace;

  position: relative;
  width: 100%;
  max-width: 440px;
  /* The closed panel keeps its size, ready to unroll, but never lengthens the page */
  contain: layout;
  /* A number, not auto, so it can wait for the panel to roll up before dropping back */
  z-index: 0;
  transition: z-index 0s linear 0.35s;
  color: var(--kz-search-fg);
}

/* Open, the field rises above what follows it (its panel included) */
.kodza-search.is-open {
  z-index: 20;
  transition-delay: 0s;
}

.kodza-search__box {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  height: var(--kz-search-height);
  padding: 0 10px 0 16px;
  border-radius: 999px;
  background: var(--kz-search-bg);
  box-shadow: inset 0 0 0 1px var(--kz-search-line);
  cursor: text;
  transition: box-shadow 0.25s ease;
}

.kodza-search__box:hover {
  box-shadow: inset 0 0 0 1px var(--kz-search-line-hover);
}

.kodza-search__box:focus-within {
  box-shadow: inset 0 0 0 1.5px var(--kz-search-fg), 0 0 0 4px var(--kz-search-soft);
}

.kodza-search__icon {
  flex: none;
  width: 16px;
  height: 16px;
  fill: none;
  stroke: var(--kz-search-muted);
  stroke-width: 1.6;
  stroke-linecap: round;
}

.kodza-search__input {
  flex: 1;
  min-width: 0;
  height: 100%;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  font-size: 15px;
  outline: none;
  appearance: none;
}

.kodza-search__input::placeholder {
  color: var(--kz-search-muted);
}

.kodza-search__input::-webkit-search-cancel-button {
  display: none;
}

/* The "/" hint gives way to a clear button once there is something to clear */
.kodza-search__key,
.kodza-search__clear {
  flex: none;
  display: grid;
  place-items: center;
  height: 26px;
  border-radius: 7px;
  transition: opacity 0.2s ease, transform 0.3s var(--kz-search-ease);
}

.kodza-search__key {
  min-width: 26px;
  padding: 0 6px;
  background: var(--kz-search-soft);
  color: var(--kz-search-muted);
  font-family: var(--kz-search-mono);
  font-size: 12px;
}

.kodza-search__clear {
  position: absolute;
  right: 10px;
  width: 26px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--kz-search-soft);
  color: var(--kz-search-muted);
  cursor: pointer;
  opacity: 0;
  transform: scale(0.6);
  visibility: hidden;
}

.kodza-search__clear svg {
  width: 11px;
  height: 11px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
}

.kodza-search.has-value .kodza-search__key {
  opacity: 0;
  transform: scale(0.6);
}

.kodza-search.has-value .kodza-search__clear {
  opacity: 1;
  transform: none;
  visibility: visible;
}

.kodza-search__clear:focus-visible {
  outline: 2px solid var(--kz-search-fg);
  outline-offset: 1px;
}

/* The suggestions unroll under the field */
.kodza-search__panel {
  position: absolute;
  top: calc(var(--kz-search-height) + 8px);
  right: 0;
  left: 0;
  z-index: 20;
  overflow: hidden;
  border-radius: 16px;
  background: var(--kz-search-bg);
  box-shadow: 0 0 0 1px var(--kz-search-line), var(--kz-search-shadow);
  visibility: hidden;
  opacity: 0;
  clip-path: inset(0 0 100% 0 round 16px);
  transform: translateY(-4px);
  transition:
    clip-path 0.35s var(--kz-search-ease),
    opacity 0.2s ease,
    transform 0.35s var(--kz-search-ease),
    visibility 0s linear 0.35s;
}

.kodza-search.is-open .kodza-search__panel {
  visibility: visible;
  opacity: 1;
  clip-path: inset(-40px -40px -60px -40px round 16px);
  transform: none;
  transition-delay: 0s;
}

/* Not enough room below: they unroll upwards, and grow upwards as you type */
.kodza-search.is-above .kodza-search__panel {
  top: auto;
  bottom: calc(var(--kz-search-height) + 8px);
  clip-path: inset(100% 0 0 0 round 16px);
  transform: translateY(4px);
}

.kodza-search.is-above.is-open .kodza-search__panel {
  clip-path: inset(-60px -40px -40px -40px round 16px);
  transform: none;
}

.kodza-search__list {
  position: relative;
  max-height: 320px;
  margin: 0;
  padding: 6px;
  overflow-y: auto;
  overscroll-behavior: contain;
  list-style: none;
}

.kodza-search__group {
  padding: 10px 12px 6px;
  font-family: var(--kz-search-mono);
  font-size: 11px;
  color: var(--kz-search-muted);
}

.kodza-search__highlight {
  position: absolute;
  top: 0;
  right: 6px;
  left: 6px;
  height: var(--kz-hl-h, 40px);
  border-radius: 10px;
  background: var(--kz-search-soft);
  opacity: var(--kz-hl-on, 0);
  transform: translateY(var(--kz-hl-y, 0));
  pointer-events: none;
}

.kodza-search.is-open .kodza-search__highlight {
  transition: transform 0.2s var(--kz-search-ease), opacity 0.15s ease;
}

.kodza-search__option {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 40px;
  padding: 0 12px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}

.kodza-search__option mark {
  background: none;
  color: inherit;
  text-decoration: underline;
  text-decoration-thickness: 1.5px;
  text-underline-offset: 3px;
}

.kodza-search__meta {
  font-family: var(--kz-search-mono);
  font-size: 11px;
  font-weight: 400;
  color: var(--kz-search-muted);
}

.kodza-search__empty {
  padding: 28px 16px 30px;
  font-size: 14px;
  color: var(--kz-search-muted);
  text-align: center;
}

.kodza-search__live {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

@media (prefers-reduced-motion: reduce) {
  .kodza-search__box,
  .kodza-search__key,
  .kodza-search__clear,
  .kodza-search__panel,
  .kodza-search.is-open .kodza-search__highlight {
    transition-duration: 0.01ms !important;
    transition-delay: 0s !important;
  }
}

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

/* kodza-guard 8da2578c017b — 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-search__clear):not(#_) {
  outline: revert;
  outline-offset: revert;
}

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

.kodza-search:not(#_),
.kodza-search__options:not(#_),
.kodza-search__panel:not(#_),
.kodza-search__live:not(#_) {
  box-sizing: revert;
}

.kodza-search__box:not(#_) {
  border: revert;
  margin: revert;
  outline: revert;
  text-decoration: revert;
  list-style: revert;
  box-sizing: revert;
  float: 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-search__icon:not(#_),
.kodza-search__clear svg:where(:not([class*="kodza-"])):not(#_) {
  border: revert;
  margin: revert;
  padding: revert;
  border-radius: revert;
  outline: revert;
  text-decoration: revert;
  transition: revert;
  list-style: revert;
  box-sizing: revert;
  float: revert;
  position: revert;
  background-color: revert;
  background-image: revert;
  box-shadow: revert;
  outline-offset: revert;
  appearance: revert;
  max-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-search__input:not(#_) {
  margin: revert;
  border-radius: revert;
  text-decoration: revert;
  transition: revert;
  list-style: revert;
  box-sizing: revert;
  float: revert;
  position: revert;
  box-shadow: revert;
  outline-offset: 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-search__key:not(#_) {
  border: revert;
  margin: revert;
  outline: revert;
  text-decoration: revert;
  list-style: revert;
  box-sizing: revert;
  float: revert;
  position: revert;
  box-shadow: 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;
}

.kodza-search__clear:not(#_) {
  margin: revert;
  text-decoration: revert;
  list-style: revert;
  box-sizing: revert;
  float: revert;
  box-shadow: revert;
  appearance: revert;
  max-width: revert;
  max-height: 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;
  white-space: revert;
  min-height: revert;
}

.kodza-search__list:not(#_) {
  border: revert;
  border-radius: revert;
  outline: revert;
  text-decoration: revert;
  transition: revert;
  box-sizing: revert;
  float: revert;
  background-color: revert;
  background-image: revert;
  box-shadow: revert;
  outline-offset: revert;
  appearance: revert;
  max-width: 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-search__options option:where(:not([class*="kodza-"])):not(#_) {
  box-sizing: revert;
  color: revert;
}

.kodza-search__icon:not(#_):where(:not([hidden])),
.kodza-search__input:not(#_):where(:not([hidden])),
.kodza-search__list:not(#_):where(:not([hidden])),
.kodza-search__clear svg:where(:not([class*="kodza-"])):not(#_):where(:not([hidden])) {
  display: revert;
}

.kodza-search__icon:not(#_):where([hidden]),
.kodza-search__input:not(#_):where([hidden]),
.kodza-search__list:not(#_):where([hidden]),
.kodza-search__clear svg:where(:not([class*="kodza-"])):not(#_):where([hidden]) {
  display: none;
}

/* 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-search:not(#_) {
  width: min(100%, 440px);
}

.kodza-search__box:not(#_) {
  position: relative;
  display: flex;
  padding: 0 10px 0 16px;
  border-radius: 999px;
  background: var(--kz-search-bg);
  box-shadow: inset 0 0 0 1px var(--kz-search-line);
  transition: box-shadow 0.25s ease;
}

.kodza-search__box:hover:not(#_) {
  box-shadow: inset 0 0 0 1px var(--kz-search-line-hover);
}

.kodza-search__box:focus-within:not(#_) {
  box-shadow: inset 0 0 0 1.5px var(--kz-search-fg), 0 0 0 4px var(--kz-search-soft);
}

.kodza-search__input:not(#_) {
  flex: 1;
  min-width: 0;
  height: 100%;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  font-size: 15px;
  outline: none;
  appearance: none;
}

.kodza-search__input:not(#_)::placeholder {
  color: var(--kz-search-muted);
}

.kodza-search__input:not(#_)::-webkit-search-cancel-button {
  display: none;
}

.kodza-search__key:not(#_) {
  display: grid;
  border-radius: 7px;
  transition: opacity 0.2s ease, transform 0.3s var(--kz-search-ease);
}

.kodza-search__clear:not(#_) {
  flex: none;
  display: grid;
  place-items: center;
  height: 26px;
  border-radius: 7px;
  transition: opacity 0.2s ease, transform 0.3s var(--kz-search-ease);
}

.kodza-search__key:not(#_) {
  padding: 0 6px;
  background: var(--kz-search-soft);
  color: var(--kz-search-muted);
  font-family: var(--kz-search-mono);
  font-size: 12px;
}

.kodza-search__clear:not(#_) {
  position: absolute;
  right: 10px;
  width: 26px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--kz-search-soft);
  color: var(--kz-search-muted);
  cursor: pointer;
  opacity: 0;
  transform: scale(0.6);
  visibility: hidden;
}

.kodza-search.has-value .kodza-search__clear:not(#_) {
  opacity: 1;
  transform: none;
  visibility: visible;
}

.kodza-search__clear:focus-visible:not(#_) {
  outline: 2px solid var(--kz-search-fg);
  outline-offset: 1px;
}

.kodza-search__list:not(#_) {
  position: relative;
  max-height: 320px;
  margin: 0;
  padding: 6px;
  list-style: none;
}

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

@media (prefers-reduced-motion: reduce) {
  .kodza-search__clear: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 — Search Autocomplete
// Turns the field into an ARIA combobox: reads the suggestions from its own <datalist> (or from
// root.kodzaSearch(query), an async function returning [{ label, meta }]), filters them by
// letters in order, underlines the matches, groups them by meta, and lets the arrows, Enter and
// Escape drive. "/" focuses the first search of the page. Fires "kodza:search" with { value }.
(() => {
  const SELECTOR = '.kodza-search';
  const reduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
  const cross = '<svg viewBox="0 0 12 12" aria-hidden="true"><path d="M3 3l6 6M9 3 3 9"/></svg>';
  let uid = 0;
  let slashTaken = false;

  // Positions of the query's letters in the text, in order, or null
  const match = (text, query) => {
    const hits = [];
    let from = 0;
    for (const char of query) {
      const at = text.indexOf(char, from);
      if (at < 0) return null;
      hits.push(at);
      from = at + 1;
    }
    return hits;
  };

  // One instance. Everything it starts is tied to `signal`, so kodza:destroy stops it all
  function mount(root, signal) {
    const input = root.querySelector('.kodza-search__input');
    const box = root.querySelector('.kodza-search__box');
    const datalist = root.querySelector('.kodza-search__options');
    if (!input || !box) return;
    const id = `kodza-search-${++uid}`;
    const local = datalist ? [...datalist.options].map((option) => ({ label: option.value, meta: option.label || '' })) : [];
    // The custom list replaces the browser's own
    input.removeAttribute('list');

    const clear = document.createElement('button');
    clear.type = 'button';
    clear.className = 'kodza-search__clear';
    clear.tabIndex = -1;
    clear.setAttribute('aria-label', 'Clear the search');
    clear.innerHTML = cross;
    box.append(clear);

    const panel = document.createElement('div');
    panel.className = 'kodza-search__panel';
    const list = document.createElement('ul');
    list.className = 'kodza-search__list';
    list.id = `${id}-list`;
    list.setAttribute('role', 'listbox');
    list.setAttribute('aria-label', 'Suggestions');
    // A list that scrolls is reachable with Tab in Chrome: here the arrows drive it, from the field
    list.tabIndex = -1;
    panel.append(list);
    const live = Object.assign(document.createElement('span'), { className: 'kodza-search__live' });
    live.setAttribute('aria-live', 'polite');
    root.append(panel, live);

    input.setAttribute('role', 'combobox');
    input.setAttribute('aria-expanded', 'false');
    input.setAttribute('aria-controls', list.id);
    input.setAttribute('aria-autocomplete', 'list');

    let items = [];
    let active = null;
    let resize = null;
    let token = 0;

    const light = (entry, scroll = true) => {
      active = entry;
      items.forEach((it) => it.el.setAttribute('aria-selected', String(it === entry)));
      if (!entry) {
        input.removeAttribute('aria-activedescendant');
        return list.style.setProperty('--kz-hl-on', 0);
      }
      input.setAttribute('aria-activedescendant', entry.el.id);
      list.style.setProperty('--kz-hl-y', `${entry.el.offsetTop}px`);
      list.style.setProperty('--kz-hl-h', `${entry.el.offsetHeight}px`);
      list.style.setProperty('--kz-hl-on', 1);
      // Scroll the list only (scrollIntoView would also nudge the page), with the row's group
      // heading when it opens the group, and the list's own padding above the very first row
      if (scroll) {
        const prev = entry.el.previousElementSibling;
        const first = prev?.classList.contains('kodza-search__group') ? prev : entry.el;
        const top = first.previousElementSibling?.classList.contains('kodza-search__highlight') ? 0 : first.offsetTop;
        const bottom = entry.el.offsetTop + entry.el.offsetHeight;
        if (top < list.scrollTop) list.scrollTop = top;
        else if (bottom > list.scrollTop + list.clientHeight) list.scrollTop = bottom - list.clientHeight;
      }
    };

    // Draw the results, grouped by meta; the panel eases to its new height
    const draw = (results, query) => {
      const from = panel.offsetHeight;
      const highlight = Object.assign(document.createElement('li'), { className: 'kodza-search__highlight' });
      highlight.setAttribute('role', 'presentation');
      list.replaceChildren(highlight);
      items = [];
      const groups = new Map();
      results.forEach((result) => {
        const key = result.meta || '';
        if (!groups.has(key)) groups.set(key, []);
        groups.get(key).push(result);
      });
      groups.forEach((group, meta) => {
        if (meta && groups.size > 1) {
          const head = Object.assign(document.createElement('li'), { className: 'kodza-search__group', textContent: meta });
          head.setAttribute('role', 'presentation');
          list.append(head);
        }
        group.forEach((result) => {
          const el = document.createElement('li');
          el.className = 'kodza-search__option';
          el.id = `${id}-option-${items.length}`;
          el.setAttribute('role', 'option');
          const label = document.createElement('span');
          const hits = query ? match(result.label.toLowerCase(), query) || [] : [];
          let last = 0;
          hits.forEach((at) => {
            label.append(result.label.slice(last, at), Object.assign(document.createElement('mark'), { textContent: result.label[at] }));
            last = at + 1;
          });
          label.append(result.label.slice(last));
          // The meta is said once by the group heading; alone, each row says it
          el.append(label, Object.assign(document.createElement('span'), { className: 'kodza-search__meta', textContent: groups.size > 1 ? '' : result.meta || '' }));
          const entry = { el, result };
          el.addEventListener('pointermove', () => active !== entry && light(entry, false), { signal });
          el.addEventListener('click', () => choose(entry), { signal });
          list.append(el);
          items.push(entry);
        });
      });
      if (!results.length) {
        const empty = Object.assign(document.createElement('li'), { className: 'kodza-search__empty', textContent: 'Nothing found. Not even a bug.' });
        empty.setAttribute('role', 'presentation');
        list.append(empty);
      }
      live.textContent = results.length ? `${results.length} suggestion${results.length > 1 ? 's' : ''}` : 'No suggestions';
      light(query ? items[0] || null : null, false);
      if (!reduceMotion && root.classList.contains('is-open')) {
        resize?.cancel();
        const to = panel.offsetHeight;
        if (Math.abs(to - from) > 1) resize = panel.animate([{ height: `${from}px` }, { height: `${to}px` }], { duration: 260, easing: 'cubic-bezier(0.22, 1, 0.36, 1)' });
      }
    };

    const search = async () => {
      const query = input.value.trim().toLowerCase();
      root.classList.toggle('has-value', input.value !== '');
      const mine = ++token;
      let results;
      if (typeof root.kodzaSearch === 'function') {
        try {
          results = await root.kodzaSearch(query);
        } catch {
          results = [];
        }
        if (mine !== token) return;
      } else {
        results = query ? local.filter((item) => match(item.label.toLowerCase(), query)) : local.slice(0, 5);
      }
      draw(results, query);
    };

    const open = () => {
      if (root.classList.contains('is-open')) return;
      search();
      // Not enough room below and more above: the suggestions open upwards. A closed panel that
      // changes side gets there at once, so it always unrolls from the field
      const field = box.getBoundingClientRect();
      const above = field.bottom + Math.min(332, panel.scrollHeight) + 16 > innerHeight && field.top > innerHeight / 2;
      if (above !== root.classList.contains('is-above')) {
        panel.style.transition = 'none';
        root.classList.toggle('is-above', above);
        void panel.offsetWidth;
        panel.style.transition = '';
      }
      root.classList.add('is-open');
      input.setAttribute('aria-expanded', 'true');
    };
    const close = () => {
      root.classList.remove('is-open');
      input.setAttribute('aria-expanded', 'false');
      light(null);
    };
    const choose = (entry) => {
      if (!entry) return;
      input.value = entry.result.label;
      root.classList.add('has-value');
      close();
      root.dispatchEvent(new CustomEvent('kodza:search', { detail: { value: entry.result.label, item: entry.result }, bubbles: true }));
    };

    input.addEventListener('focus', open, { signal });
    input.addEventListener('input', () => {
      if (!root.classList.contains('is-open')) open();
      else search();
    }, { signal });
    input.addEventListener('keydown', (event) => {
      const index = items.indexOf(active);
      if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
        event.preventDefault();
        open();
        // From nothing highlighted, the first one down or the last one up
        const to = index < 0 ? (event.key === 'ArrowDown' ? 0 : -1) : index + (event.key === 'ArrowDown' ? 1 : -1);
        if (items.length) light(items[(to + items.length) % items.length]);
      } else if (event.key === 'Enter') {
        if (active && root.classList.contains('is-open')) {
          event.preventDefault();
          choose(active);
        }
      } else if (event.key === 'Escape') {
        if (root.classList.contains('is-open')) close();
        else {
          input.value = '';
          root.classList.remove('has-value');
        }
      } else if (event.key === 'Tab') {
        close();
      }
    }, { signal });
    clear.addEventListener('click', () => {
      input.value = '';
      root.classList.remove('has-value');
      input.focus();
      search();
    }, { signal });
    panel.addEventListener('mousedown', (event) => event.preventDefault(), { signal });
    document.addEventListener('pointerdown', (event) => !root.contains(event.target) && close(), { signal });

    if (!slashTaken) {
      slashTaken = true;
      document.addEventListener('keydown', (event) => {
        if (event.key !== '/' || event.target.closest?.('input, textarea, select, [contenteditable]')) return;
        event.preventDefault();
        input.focus();
      }, { signal });
      // Stopped, it hands "/" to the next search started
      signal.addEventListener('abort', () => (slashTaken = false));
    }

    root.classList.toggle('has-value', input.value !== '');
  }

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