# Text Field

> A text field whose label folds up as you type. A button clears it, a check draws itself once it is valid, and the hint gives way to the error.

Forms · input, form, validation, label · HTML, CSS, vanilla JS · no dependencies · updated 2026-10-17
Demo: https://kodza.dev/components/text-field/

## Files

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

- [`kodza-text-field.css`](https://kodza.dev/registry/text-field/kodza-text-field.css) · 15.7 KB
- [`kodza-text-field.js`](https://kodza.dev/registry/text-field/kodza-text-field.js) · 3.5 KB
- [`kodza-text-field.html`](https://kodza.dev/registry/text-field/kodza-text-field.html) · 1.9 KB · the markup, to adapt and paste into your page

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

```bash
curl -fsSL --create-dirs -o kodza/kodza-text-field.css https://kodza.dev/registry/text-field/kodza-text-field.css
curl -fsSL --create-dirs -o kodza/kodza-text-field.js https://kodza.dev/registry/text-field/kodza-text-field.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-field`
- Variables (set them on the root element itself: it declares its own defaults):
  - `--kz-field-bg: #ffffff`
  - `--kz-field-fg: #0a0a0a`
  - `--kz-field-muted: rgba(10, 10, 10, 0.6)`
  - `--kz-field-line: rgba(10, 10, 10, 0.14)`
  - `--kz-field-line-hover: rgba(10, 10, 10, 0.3)`
  - `--kz-field-focus: #0a0a0a`
  - `--kz-field-error: #0a0a0a`
  - `--kz-field-disabled: rgba(10, 10, 10, 0.04)`
  - `--kz-field-height: 56px`
  - `--kz-field-radius: 12px`
  - `--kz-field-pad: 16px`
  - `--kz-field-ease: cubic-bezier(0.22, 1, 0.36, 1)`
- Attributes:
  - `data-error` (e.g. `That does not look like an email.`, `Lowercase letters, digits and dashes only.`)
- Lifecycle: `kodza:init` / `kodza:destroy` on `document`, with `{ detail: { root } }` to target a container.

## Dark mode

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

```css
@media (prefers-color-scheme: dark) {
  .kodza-field {
    --kz-field-bg: #161616;
    --kz-field-fg: #f2f2f0;
    --kz-field-muted: rgba(242, 242, 240, 0.62);
    --kz-field-line: rgba(255, 255, 255, 0.14);
    --kz-field-line-hover: rgba(255, 255, 255, 0.3);
    --kz-field-focus: #f2f2f0;
    --kz-field-error: #f2f2f0;
    --kz-field-disabled: rgba(255, 255, 255, 0.06);
  }
}
```

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

## Use it

### Plain HTML page

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

export type TextFieldProps = Omit<ComponentPropsWithoutRef<'div'>, "children" | "vars"> & {
  /** Settings, as CSS variables on the root */
  vars?: {
    /** default: #ffffff */
    "--kz-field-bg"?: string | number;
    /** default: #0a0a0a */
    "--kz-field-fg"?: string | number;
    /** default: rgba(10, 10, 10, 0.6) */
    "--kz-field-muted"?: string | number;
    /** default: rgba(10, 10, 10, 0.14) */
    "--kz-field-line"?: string | number;
    /** default: rgba(10, 10, 10, 0.3) */
    "--kz-field-line-hover"?: string | number;
    /** default: #0a0a0a */
    "--kz-field-focus"?: string | number;
    /** default: #0a0a0a */
    "--kz-field-error"?: string | number;
    /** default: rgba(10, 10, 10, 0.04) */
    "--kz-field-disabled"?: string | number;
    /** default: 56px */
    "--kz-field-height"?: string | number;
    /** default: 12px */
    "--kz-field-radius"?: string | number;
    /** default: 16px */
    "--kz-field-pad"?: string | number;
    /** default: cubic-bezier(0.22, 1, 0.36, 1) */
    "--kz-field-ease"?: string | number;
  };
  className?: string;
};

export function TextField({ vars, className, style, ...rest }: TextFieldProps) {
  const ref = useRef<ComponentRef<'div'>>(null);
  const classes = ["kodza-field", 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('./text-field.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}>
      <label className="kodza-field__box">
        <input className="kodza-field__input" type="email" name="email" placeholder=" " autoComplete="email" required data-error="That does not look like an email." />
        {' '}
        <span className="kodza-field__label">Email</span>
        {' '}
        <svg className="kodza-field__check" viewBox="0 0 16 16" aria-hidden="true">
          <path d="M3.5 8.5l3 3 6-7" pathLength="1" />
        </svg>
      </label>
      {' '}
      <button className="kodza-field__clear" type="button" tabIndex={-1} aria-label="Clear the field">
        <svg viewBox="0 0 16 16" aria-hidden="true">
          <path d="M5 5l6 6M11 5l-6 6" />
        </svg>
      </button>
      <p className="kodza-field__note">
        <span className="kodza-field__hint">We only write when something ships.</span>
        <span className="kodza-field__error" aria-live="polite" />
      </p>
    </div>
  );
}
```

## Code

```html
<div class="kodza-field">
  <label class="kodza-field__box">
    <input class="kodza-field__input" type="email" name="email" placeholder=" " autocomplete="email" required data-error="That does not look like an email.">
    <span class="kodza-field__label">Email</span>
    <svg class="kodza-field__check" viewBox="0 0 16 16" aria-hidden="true"><path d="M3.5 8.5l3 3 6-7" pathLength="1"/></svg>
  </label>
  <button class="kodza-field__clear" type="button" tabindex="-1" aria-label="Clear the field"><svg viewBox="0 0 16 16" aria-hidden="true"><path d="M5 5l6 6M11 5l-6 6"/></svg></button>
  <p class="kodza-field__note"><span class="kodza-field__hint">We only write when something ships.</span><span class="kodza-field__error" aria-live="polite"></span></p>
</div>

<div class="kodza-field">
  <label class="kodza-field__box">
    <span class="kodza-field__prefix">kodza.dev/</span>
    <input class="kodza-field__input" type="text" name="handle" placeholder=" " autocomplete="username" required pattern="[a-z0-9\-]+" minlength="2" data-error="Lowercase letters, digits and dashes only.">
    <span class="kodza-field__label">Username</span>
    <svg class="kodza-field__check" viewBox="0 0 16 16" aria-hidden="true"><path d="M3.5 8.5l3 3 6-7" pathLength="1"/></svg>
  </label>
  <button class="kodza-field__clear" type="button" tabindex="-1" aria-label="Clear the field"><svg viewBox="0 0 16 16" aria-hidden="true"><path d="M5 5l6 6M11 5l-6 6"/></svg></button>
  <p class="kodza-field__note"><span class="kodza-field__hint">Lowercase, no spaces. Like your variable names.</span><span class="kodza-field__error" aria-live="polite"></span></p>
</div>

<div class="kodza-field">
  <label class="kodza-field__box">
    <input class="kodza-field__input" type="text" name="plan" placeholder=" " value="Free, forever" disabled>
    <span class="kodza-field__label">Plan</span>
  </label>
  <p class="kodza-field__note"><span class="kodza-field__hint">There is no other plan.</span></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 — Text Field
   A text field whose label sits inside it, then folds up above the text as soon as you type or
   focus it. A button clears it, a check draws itself once the value is valid, and the hint
   gives way to the error message (from data-error) when it is not, without anything moving.
   A prefix (kodza.dev/) slides in with the label. The clear button stays out of the Tab order
   (from the keyboard, select all and delete), so Tab always leaves the field. Errors are monochrome by default: an icon and
   a message, never colour alone (set --kz-field-error to use a red).
   Everything is tuned with the --kz-field-* variables. */
.kodza-field {
  --kz-field-bg: #ffffff;
  --kz-field-fg: #0a0a0a;
  --kz-field-muted: rgba(10, 10, 10, 0.6);
  --kz-field-line: rgba(10, 10, 10, 0.14);
  --kz-field-line-hover: rgba(10, 10, 10, 0.3);
  --kz-field-focus: #0a0a0a;
  --kz-field-error: #0a0a0a;
  --kz-field-disabled: rgba(10, 10, 10, 0.04);
  --kz-field-height: 56px;
  --kz-field-radius: 12px;
  --kz-field-pad: 16px;
  --kz-field-ease: cubic-bezier(0.22, 1, 0.36, 1);

  position: relative;
  display: grid;
  gap: 8px;
  width: 100%;
  max-width: 420px;
  color: var(--kz-field-fg);
}

/* The box: the whole thing is the label, so a click anywhere focuses the input */
.kodza-field__box {
  position: relative;
  display: flex;
  align-items: flex-end;
  box-sizing: border-box;
  height: var(--kz-field-height);
  padding: 0 var(--kz-field-pad) 9px;
  border-radius: var(--kz-field-radius);
  background: var(--kz-field-bg);
  box-shadow: inset 0 0 0 1px var(--kz-field-line);
  cursor: text;
  transition: box-shadow 0.25s ease;
}

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

.kodza-field__box:focus-within {
  box-shadow: inset 0 0 0 1.5px var(--kz-field-focus), 0 0 0 4px var(--kz-field-disabled);
}

.kodza-field__input {
  flex: 1;
  min-width: 0;
  height: 22px;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  font-size: 15px;
  line-height: 22px;
  outline: none;
}

/* The label: inside the box at rest, folded up above the text once focused or filled */
.kodza-field__label {
  position: absolute;
  top: 50%;
  left: var(--kz-field-pad);
  color: var(--kz-field-muted);
  font-size: 15px;
  line-height: 1;
  white-space: nowrap;
  pointer-events: none;
  transform: translateY(-50%);
  transform-origin: left top;
  transition: transform 0.35s var(--kz-field-ease), color 0.25s ease;
}

.kodza-field__box:focus-within .kodza-field__label,
.kodza-field__input:not(:placeholder-shown) ~ .kodza-field__label {
  color: var(--kz-field-muted);
  transform: translateY(-18px) scale(0.8);
}

/* A prefix waits with the label, then comes in */
.kodza-field__prefix {
  flex: none;
  color: var(--kz-field-muted);
  font-size: 15px;
  line-height: 22px;
  opacity: 0;
  transform: translateX(-4px);
  transition: opacity 0.25s ease, transform 0.35s var(--kz-field-ease);
}

.kodza-field__box:focus-within .kodza-field__prefix,
.kodza-field__box:has(.kodza-field__input:not(:placeholder-shown)) .kodza-field__prefix {
  opacity: 1;
  transform: none;
}

/* The check: drawn once the value is valid */
.kodza-field__check {
  position: absolute;
  top: 50%;
  right: var(--kz-field-pad);
  width: 16px;
  height: 16px;
  fill: none;
  stroke: var(--kz-field-fg);
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  transform: translateY(-50%);
  transition: stroke-dashoffset 0.4s var(--kz-field-ease);
}

.kodza-field__input[aria-invalid="false"]:not(:placeholder-shown) ~ .kodza-field__check {
  stroke-dashoffset: 0;
  transition-delay: 0.1s;
}

/* The clear button: in when there is something to clear (and no check to show) */
.kodza-field__clear {
  position: absolute;
  top: calc(var(--kz-field-height) / 2 - 14px);
  right: 10px;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--kz-field-disabled);
  color: var(--kz-field-muted);
  white-space: nowrap;
  cursor: pointer;
  opacity: 0;
  transform: scale(0.6);
  visibility: hidden;
  transition: opacity 0.2s ease, transform 0.3s var(--kz-field-ease), visibility 0s linear 0.3s, color 0.2s ease;
}

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

.kodza-field__clear:hover {
  color: var(--kz-field-fg);
}

.kodza-field:has(.kodza-field__box:focus-within .kodza-field__input:not(:placeholder-shown)) .kodza-field__clear,
.kodza-field:has(.kodza-field__input:not(:placeholder-shown)):focus-within .kodza-field__clear {
  opacity: 1;
  transform: none;
  visibility: visible;
  transition-delay: 0s;
}

/* While the clear button shows, the check steps aside */
.kodza-field:focus-within .kodza-field__check {
  opacity: 0;
}

.kodza-field__clear:focus-visible {
  outline: 2px solid var(--kz-field-focus);
  outline-offset: 2px;
}

/* The note: the hint and the error share one line, and swap */
.kodza-field__note {
  display: grid;
  margin: 0;
  padding: 0 2px;
  overflow: hidden;
  font-size: 13px;
  line-height: 1.4;
}

.kodza-field__hint,
.kodza-field__error {
  grid-area: 1 / 1;
  transition: opacity 0.25s ease, transform 0.4s var(--kz-field-ease);
}

.kodza-field__hint {
  color: var(--kz-field-muted);
}

.kodza-field__error {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--kz-field-error);
  font-weight: 500;
  opacity: 0;
  transform: translateY(100%);
}

.kodza-field__error::before {
  content: "";
  flex: none;
  width: 14px;
  height: 14px;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Ccircle cx='8' cy='8' r='6.5' fill='none' stroke='black' stroke-width='1.5'/%3E%3Cpath d='M8 4.5v4.2M8 10.9v.1' stroke='black' stroke-width='1.6' stroke-linecap='round'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Ccircle cx='8' cy='8' r='6.5' fill='none' stroke='black' stroke-width='1.5'/%3E%3Cpath d='M8 4.5v4.2M8 10.9v.1' stroke='black' stroke-width='1.6' stroke-linecap='round'/%3E%3C/svg%3E") center / contain no-repeat;
}

/* Invalid (judged when the visitor leaves the field, then live while they fix it): a firmer
   outline, and the error replaces the hint */
.kodza-field:has(.kodza-field__input[aria-invalid="true"]) .kodza-field__box {
  box-shadow: inset 0 0 0 1.5px var(--kz-field-error);
}

.kodza-field:has(.kodza-field__input[aria-invalid="true"]) .kodza-field__hint {
  opacity: 0;
  transform: translateY(-100%);
}

.kodza-field:has(.kodza-field__input[aria-invalid="true"]) .kodza-field__error {
  opacity: 1;
  transform: none;
}

/* Disabled */
.kodza-field__box:has(.kodza-field__input:disabled) {
  background: var(--kz-field-disabled);
  box-shadow: none;
  color: var(--kz-field-muted);
  cursor: not-allowed;
}

.kodza-field__input:disabled {
  cursor: not-allowed;
}

@media (prefers-reduced-motion: reduce) {
  .kodza-field__box,
  .kodza-field__label,
  .kodza-field__prefix,
  .kodza-field__check,
  .kodza-field__clear,
  .kodza-field__hint,
  .kodza-field__error {
    transition-duration: 0.01ms !important;
    transition-delay: 0s !important;
  }
}

/* Theming example — on a dark background:
.dark-section .kodza-field {
  --kz-field-bg: #161616;
  --kz-field-fg: #f2f2f0;
  --kz-field-muted: rgba(242, 242, 240, 0.62);
  --kz-field-line: rgba(255, 255, 255, 0.14);
  --kz-field-line-hover: rgba(255, 255, 255, 0.3);
  --kz-field-focus: #f2f2f0;
  --kz-field-error: #f2f2f0;
  --kz-field-disabled: rgba(255, 255, 255, 0.06);
}
*/

/* kodza-guard 2e819d51de55 — 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-field__box):not(#_) {
  color: revert;
}

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

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

.kodza-field:not(#_),
.kodza-field__label:not(#_),
.kodza-field__hint:not(#_),
.kodza-field__error:not(#_),
.kodza-field__prefix:not(#_) {
  box-sizing: revert;
}

.kodza-field__box:not(#_) {
  border: revert;
  margin: revert;
  outline: revert;
  text-decoration: revert;
  list-style: revert;
  float: revert;
  outline-offset: 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;
}

.kodza-field__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;
  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-field__check:not(#_) {
  border: revert;
  margin: revert;
  padding: revert;
  border-radius: revert;
  outline: revert;
  text-decoration: revert;
  list-style: revert;
  box-sizing: revert;
  float: 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-field__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;
  min-height: revert;
}

.kodza-field__note:not(#_) {
  border: 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-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-field__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-field__input:not(#_):where(:not([hidden])),
.kodza-field__check:not(#_):where(:not([hidden])),
.kodza-field__clear svg:where(:not([class*="kodza-"])):not(#_):where(:not([hidden])) {
  display: revert;
}

.kodza-field__input:not(#_):where([hidden]),
.kodza-field__check:not(#_):where([hidden]),
.kodza-field__clear svg:where(:not([class*="kodza-"])):not(#_):where([hidden]) {
  display: none;
}

.kodza-field__error: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-field:not(#_) {
  width: min(100%, 420px);
}

.kodza-field__box:not(#_) {
  position: relative;
  display: flex;
  box-sizing: border-box;
  padding: 0 var(--kz-field-pad) 9px;
  border-radius: var(--kz-field-radius);
  background: var(--kz-field-bg);
  box-shadow: inset 0 0 0 1px var(--kz-field-line);
  transition: box-shadow 0.25s ease;
}

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

.kodza-field__box:focus-within:not(#_) {
  box-shadow: inset 0 0 0 1.5px var(--kz-field-focus), 0 0 0 4px var(--kz-field-disabled);
}

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

.kodza-field__check:not(#_) {
  position: absolute;
  transition: stroke-dashoffset 0.4s var(--kz-field-ease);
}

.kodza-field__input[aria-invalid="false"]:not(:placeholder-shown) ~ .kodza-field__check:not(#_) {
  transition-delay: 0.1s;
}

.kodza-field__clear:not(#_) {
  position: absolute;
  top: calc(var(--kz-field-height) / 2 - 14px);
  right: 10px;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--kz-field-disabled);
  color: var(--kz-field-muted);
  white-space: nowrap;
  cursor: pointer;
  opacity: 0;
  transform: scale(0.6);
  visibility: hidden;
  transition: opacity 0.2s ease, transform 0.3s var(--kz-field-ease), visibility 0s linear 0.3s, color 0.2s ease;
}

.kodza-field__clear:hover:not(#_) {
  color: var(--kz-field-fg);
}

.kodza-field:has(.kodza-field__box:focus-within .kodza-field__input:not(:placeholder-shown)) .kodza-field__clear:not(#_),
.kodza-field:has(.kodza-field__input:not(:placeholder-shown)):focus-within .kodza-field__clear:not(#_) {
  opacity: 1;
  transform: none;
  visibility: visible;
  transition-delay: 0s;
}

.kodza-field__clear:focus-visible:not(#_) {
  outline: 2px solid var(--kz-field-focus);
  outline-offset: 2px;
}

.kodza-field__note:not(#_) {
  display: grid;
  margin: 0;
  padding: 0 2px;
  font-size: 13px;
  line-height: 1.4;
}

.kodza-field:has(.kodza-field__input[aria-invalid="true"]) .kodza-field__box:not(#_) {
  box-shadow: inset 0 0 0 1.5px var(--kz-field-error);
}

.kodza-field__box:has(.kodza-field__input:disabled):not(#_) {
  background: var(--kz-field-disabled);
  box-shadow: none;
  color: var(--kz-field-muted);
}

.kodza-field__input:disabled:not(#_) {
  cursor: not-allowed;
}

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

@media (prefers-reduced-motion: reduce) {
  .kodza-field__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 — Text Field
// Wires the hint and the error to the input (aria-describedby, ids made here), writes the
// error message (data-error, or the browser's own) when the value is invalid, and clears the
// field from its button. The folding label, the check and the swaps are CSS.
(() => {
  const SELECTOR = '.kodza-field';
  let uid = 0;

  // One instance. Everything it starts is tied to `signal`, so kodza:destroy stops it all
  function mount(root, signal) {
    const input = root.querySelector('.kodza-field__input');
    const hint = root.querySelector('.kodza-field__hint');
    const error = root.querySelector('.kodza-field__error');
    const clear = root.querySelector('.kodza-field__clear');
    if (!input) return;
    const prefix = `kodza-field-${++uid}`;
    const described = [];
    if (hint) described.push((hint.id = `${prefix}-hint`));
    if (error) described.push((error.id = `${prefix}-error`));
    if (described.length) input.setAttribute('aria-describedby', described.join(' '));

    const check = () => {
      if (!error) return;
      const bad = !input.validity.valid;
      error.textContent = bad ? input.dataset.error || input.validationMessage : '';
      input.setAttribute('aria-invalid', String(bad));
    };
    // Judged when the visitor leaves the field, then live while they fix it
    input.addEventListener('blur', check, { signal });
    input.addEventListener('input', () => input.getAttribute('aria-invalid') === 'true' && check(), { signal });
    input.addEventListener('invalid', check, { signal });

    clear?.addEventListener('click', () => {
      input.value = '';
      input.dispatchEvent(new Event('input', { bubbles: true }));
      if (error) error.textContent = '';
      input.removeAttribute('aria-invalid');
      input.focus();
    }, { signal });
  }

  // Kodza lifecycle, the same in every component: `kodza:init` starts the instances inside
  // event.detail.root (the whole page by default), `kodza:destroy` stops them and puts their
  // markup back. For themes and apps that swap content without a page load.
  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).
