# Password

> A password field with an eye that crosses itself out, a meter that fills as it gets stronger, a verdict that rolls and rules that tick themselves off.

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

## Files

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

- [`kodza-password-field.css`](https://kodza.dev/registry/password-field/kodza-password-field.css) · 14.9 KB
- [`kodza-password-field.js`](https://kodza.dev/registry/password-field/kodza-password-field.js) · 5.6 KB
- [`kodza-password-field.html`](https://kodza.dev/registry/password-field/kodza-password-field.html) · 1.4 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-password-field.css https://kodza.dev/registry/password-field/kodza-password-field.css
curl -fsSL --create-dirs -o kodza/kodza-password-field.js https://kodza.dev/registry/password-field/kodza-password-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-password`
- Variables (set them on the root element itself: it declares its own defaults):
  - `--kz-pass-bg: #ffffff`
  - `--kz-pass-fg: #0a0a0a`
  - `--kz-pass-muted: rgba(10, 10, 10, 0.6)`
  - `--kz-pass-line: rgba(10, 10, 10, 0.14)`
  - `--kz-pass-line-hover: rgba(10, 10, 10, 0.3)`
  - `--kz-pass-soft: rgba(10, 10, 10, 0.06)`
  - `--kz-pass-height: 56px`
  - `--kz-pass-radius: 12px`
  - `--kz-pass-pad: 16px`
  - `--kz-pass-ease: cubic-bezier(0.22, 1, 0.36, 1)`
- Attributes:
  - `data-rule` (e.g. `length`, `digit`, `symbol`)
- Events: `kodza:strength` (bubbling, from the root)
- 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-password {
    --kz-pass-bg: #161616;
    --kz-pass-fg: #f2f2f0;
    --kz-pass-muted: rgba(242, 242, 240, 0.62);
    --kz-pass-line: rgba(255, 255, 255, 0.14);
    --kz-pass-line-hover: rgba(255, 255, 255, 0.3);
    --kz-pass-soft: rgba(255, 255, 255, 0.08);
  }
}
```

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

## Use it

### Plain HTML page

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

export type PasswordProps = Omit<ComponentPropsWithoutRef<'div'>, "children" | "vars" | "onStrength"> & {
  /** Settings, as CSS variables on the root */
  vars?: {
    /** default: #ffffff */
    "--kz-pass-bg"?: string | number;
    /** default: #0a0a0a */
    "--kz-pass-fg"?: string | number;
    /** default: rgba(10, 10, 10, 0.6) */
    "--kz-pass-muted"?: string | number;
    /** default: rgba(10, 10, 10, 0.14) */
    "--kz-pass-line"?: string | number;
    /** default: rgba(10, 10, 10, 0.3) */
    "--kz-pass-line-hover"?: string | number;
    /** default: rgba(10, 10, 10, 0.06) */
    "--kz-pass-soft"?: string | number;
    /** default: 56px */
    "--kz-pass-height"?: string | number;
    /** default: 12px */
    "--kz-pass-radius"?: string | number;
    /** default: 16px */
    "--kz-pass-pad"?: string | number;
    /** default: cubic-bezier(0.22, 1, 0.36, 1) */
    "--kz-pass-ease"?: string | number;
  };
  /** "kodza:strength", fired by the script (bubbles from the root) */
  onStrength?: (event: CustomEvent) => void;
  className?: string;
};

export function Password({ vars, onStrength, className, style, ...rest }: PasswordProps) {
  const ref = useRef<ComponentRef<'div'>>(null);
  const classes = ["kodza-password", 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('./password-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]);

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

  return (
    <div key={key} {...rest} className={classes} style={{ ...vars, ...style } as CSSProperties} ref={ref}>
      <div className="kodza-password__field">
        <label className="kodza-password__box">
          <input className="kodza-password__input" type="password" name="password" placeholder=" " autoComplete="new-password" minLength={8} required />
          {' '}
          <span className="kodza-password__label">Password</span>
        </label>
        {' '}
        <button className="kodza-password__toggle" type="button" aria-label="Show the password" aria-pressed="false">
          <svg viewBox="0 0 20 20" aria-hidden="true">
            <path d="M1.8 10S5 4.5 10 4.5 18.2 10 18.2 10 15 15.5 10 15.5 1.8 10 1.8 10Z" />
            <circle cx="10" cy="10" r="2.6" />
            <path className="kodza-password__slash" d="M3.5 3.5l13 13" pathLength="1" />
          </svg>
        </button>
      </div>
      <div className="kodza-password__meter" aria-hidden="true">
        <span />
        <span />
        <span />
        <span />
      </div>
      <p className="kodza-password__status">
        <span className="kodza-password__word">Type something</span>
      </p>
      <ul className="kodza-password__rules">
        <li className="kodza-password__rule" data-rule="length"><svg viewBox="0 0 16 16" aria-hidden="true"> <path d="M3.5 8.5l3 3 6-7" pathLength="1" /> </svg>At least 8 characters</li>
        <li className="kodza-password__rule" data-rule="digit"><svg viewBox="0 0 16 16" aria-hidden="true"> <path d="M3.5 8.5l3 3 6-7" pathLength="1" /> </svg>A number</li>
        <li className="kodza-password__rule" data-rule="symbol"><svg viewBox="0 0 16 16" aria-hidden="true"> <path d="M3.5 8.5l3 3 6-7" pathLength="1" /> </svg>A symbol, like ! or #</li>
      </ul>
    </div>
  );
}
```

## Code

```html
<div class="kodza-password">
  <div class="kodza-password__field">
    <label class="kodza-password__box">
      <input class="kodza-password__input" type="password" name="password" placeholder=" " autocomplete="new-password" minlength="8" required>
      <span class="kodza-password__label">Password</span>
    </label>
    <button class="kodza-password__toggle" type="button" aria-label="Show the password" aria-pressed="false">
      <svg viewBox="0 0 20 20" aria-hidden="true"><path d="M1.8 10S5 4.5 10 4.5 18.2 10 18.2 10 15 15.5 10 15.5 1.8 10 1.8 10Z"/><circle cx="10" cy="10" r="2.6"/><path class="kodza-password__slash" d="M3.5 3.5l13 13" pathLength="1"/></svg>
    </button>
  </div>
  <div class="kodza-password__meter" aria-hidden="true"><span></span><span></span><span></span><span></span></div>
  <p class="kodza-password__status"><span class="kodza-password__word">Type something</span></p>
  <ul class="kodza-password__rules">
    <li class="kodza-password__rule" data-rule="length"><svg viewBox="0 0 16 16" aria-hidden="true"><path d="M3.5 8.5l3 3 6-7" pathLength="1"/></svg>At least 8 characters</li>
    <li class="kodza-password__rule" data-rule="digit"><svg viewBox="0 0 16 16" aria-hidden="true"><path d="M3.5 8.5l3 3 6-7" pathLength="1"/></svg>A number</li>
    <li class="kodza-password__rule" data-rule="symbol"><svg viewBox="0 0 16 16" aria-hidden="true"><path d="M3.5 8.5l3 3 6-7" pathLength="1"/></svg>A symbol, like ! or #</li>
  </ul>
</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 — Password
   A password field with everything around it: an eye to show it (a stroke crosses the eye
   while it is visible), a four-step meter that fills as it gets stronger with its word rolling
   to the new verdict, and rules that tick themselves off one by one.
   Same box as Text Field. Everything is tuned with the --kz-pass-* variables. */
.kodza-password {
  --kz-pass-bg: #ffffff;
  --kz-pass-fg: #0a0a0a;
  --kz-pass-muted: rgba(10, 10, 10, 0.6);
  --kz-pass-line: rgba(10, 10, 10, 0.14);
  --kz-pass-line-hover: rgba(10, 10, 10, 0.3);
  --kz-pass-soft: rgba(10, 10, 10, 0.06);
  --kz-pass-height: 56px;
  --kz-pass-radius: 12px;
  --kz-pass-pad: 16px;
  --kz-pass-ease: cubic-bezier(0.22, 1, 0.36, 1);

  display: grid;
  gap: 12px;
  width: 100%;
  max-width: 420px;
  color: var(--kz-pass-fg);
}

.kodza-password__field {
  position: relative;
}

.kodza-password__box {
  position: relative;
  display: flex;
  align-items: flex-end;
  box-sizing: border-box;
  height: var(--kz-pass-height);
  padding: 0 56px 9px var(--kz-pass-pad);
  border-radius: var(--kz-pass-radius);
  background: var(--kz-pass-bg);
  box-shadow: inset 0 0 0 1px var(--kz-pass-line);
  cursor: text;
  transition: box-shadow 0.25s ease;
}

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

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

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

.kodza-password__label {
  position: absolute;
  top: 50%;
  left: var(--kz-pass-pad);
  color: var(--kz-pass-muted);
  font-size: 15px;
  line-height: 1;
  pointer-events: none;
  transform: translateY(-50%);
  transform-origin: left top;
  transition: transform 0.35s var(--kz-pass-ease);
}

.kodza-password__box:focus-within .kodza-password__label,
.kodza-password__input:not(:placeholder-shown) ~ .kodza-password__label {
  transform: translateY(-18px) scale(0.8);
}

/* The eye: a stroke draws across it while the password is visible */
.kodza-password__toggle {
  position: absolute;
  top: calc(var(--kz-pass-height) / 2 - 18px);
  right: 10px;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--kz-pass-muted);
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.kodza-password__toggle:hover {
  background: var(--kz-pass-soft);
  color: var(--kz-pass-fg);
}

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

.kodza-password__toggle svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.kodza-password__slash {
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  transition: stroke-dashoffset 0.35s var(--kz-pass-ease);
}

.kodza-password__toggle[aria-pressed="true"] .kodza-password__slash {
  stroke-dashoffset: 0;
}

/* The meter: four steps, each filling from the left in turn */
.kodza-password__meter {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.kodza-password__meter span {
  height: 3px;
  overflow: hidden;
  border-radius: 3px;
  background: var(--kz-pass-soft);
}

.kodza-password__meter span::after {
  content: "";
  display: block;
  height: 100%;
  background: var(--kz-pass-fg);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.45s var(--kz-pass-ease) var(--d, 0ms);
}

.kodza-password__meter span.is-on::after {
  transform: none;
}

/* The verdict rolls to its new word */
.kodza-password__status {
  display: flex;
  margin: -4px 0 0;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px;
  color: var(--kz-pass-muted);
}

.kodza-password__word {
  display: inline-grid;
  overflow: hidden;
}

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

/* The rules tick themselves off */
.kodza-password__rules {
  display: grid;
  gap: 6px;
  margin: 4px 0 0;
  padding: 0;
  list-style: none;
  font-size: 13px;
  color: var(--kz-pass-muted);
}

.kodza-password__rule {
  display: flex;
  align-items: center;
  gap: 8px;
  transition: color 0.3s ease;
}

.kodza-password__rule svg {
  flex: none;
  width: 16px;
  height: 16px;
  padding: 2px;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px var(--kz-pass-line);
  box-sizing: border-box;
  fill: none;
  stroke: var(--kz-pass-bg);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  transition: background-color 0.25s ease, box-shadow 0.25s ease, stroke-dashoffset 0.4s var(--kz-pass-ease) 0.1s;
}

.kodza-password__rule.is-met {
  color: var(--kz-pass-fg);
}

.kodza-password__rule.is-met svg {
  background: var(--kz-pass-fg);
  box-shadow: none;
  stroke-dashoffset: 0;
}

@media (prefers-reduced-motion: reduce) {
  .kodza-password__box,
  .kodza-password__label,
  .kodza-password__slash,
  .kodza-password__meter span::after,
  .kodza-password__rule,
  .kodza-password__rule svg {
    transition-duration: 0.01ms !important;
    transition-delay: 0s !important;
  }
}

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

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

:where(.kodza-password__rule):not(#_) {
  color: revert;
}

:where(.kodza-password__rule svg:where(:not([class*="kodza-"]))):not(#_) {
  background-color: revert;
  background-image: revert;
}

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

.kodza-password:not(#_),
.kodza-password__field:not(#_),
.kodza-password__label:not(#_),
.kodza-password__slash:not(#_),
.kodza-password__meter:not(#_),
.kodza-password__word:not(#_),
.kodza-password__meter span:where(:not([class*="kodza-"])):not(#_),
.kodza-password__word span:where(:not([class*="kodza-"])):not(#_) {
  box-sizing: revert;
}

.kodza-password__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;
  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-password__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;
  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-password__toggle: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-password__status: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-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-password__rules:not(#_) {
  border: revert;
  border-radius: revert;
  outline: revert;
  text-decoration: revert;
  transition: 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-password__rule:not(#_) {
  border: revert;
  margin: revert;
  padding: revert;
  border-radius: revert;
  outline: revert;
  text-decoration: revert;
  list-style: revert;
  box-sizing: revert;
  float: revert;
  position: revert;
  background-color: revert;
  background-image: revert;
  box-shadow: revert;
  outline-offset: revert;
  appearance: revert;
  max-width: revert;
  max-height: revert;
  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-password__toggle 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-password__rule svg:where(:not([class*="kodza-"])):not(#_) {
  border: revert;
  margin: revert;
  outline: revert;
  text-decoration: revert;
  list-style: revert;
  float: revert;
  position: 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-password__input:not(#_):where(:not([hidden])),
.kodza-password__toggle svg:where(:not([class*="kodza-"])):not(#_):where(:not([hidden])),
.kodza-password__rule svg:where(:not([class*="kodza-"])):not(#_):where(:not([hidden])) {
  display: revert;
}

.kodza-password__input:not(#_):where([hidden]),
.kodza-password__toggle svg:where(:not([class*="kodza-"])):not(#_):where([hidden]),
.kodza-password__rule 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-password:not(#_) {
  width: min(100%, 420px);
}

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

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

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

.kodza-password__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;
  letter-spacing: 0.02em;
  outline: none;
}

.kodza-password__toggle:not(#_) {
  position: absolute;
  top: calc(var(--kz-pass-height) / 2 - 18px);
  right: 10px;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--kz-pass-muted);
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.kodza-password__toggle:hover:not(#_) {
  background: var(--kz-pass-soft);
  color: var(--kz-pass-fg);
}

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

.kodza-password__status:not(#_) {
  display: flex;
  margin: -4px 0 0;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px;
  color: var(--kz-pass-muted);
}

.kodza-password__rules:not(#_) {
  display: grid;
  margin: 4px 0 0;
  padding: 0;
  list-style: none;
  font-size: 13px;
  color: var(--kz-pass-muted);
}

.kodza-password__rule:not(#_) {
  display: flex;
  transition: color 0.3s ease;
}

.kodza-password__rule svg:not(#_) {
  padding: 2px;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px var(--kz-pass-line);
  box-sizing: border-box;
  transition: background-color 0.25s ease, box-shadow 0.25s ease, stroke-dashoffset 0.4s var(--kz-pass-ease) 0.1s;
}

.kodza-password__rule.is-met:not(#_) {
  color: var(--kz-pass-fg);
}

.kodza-password__rule.is-met svg:not(#_) {
  background: var(--kz-pass-fg);
  box-shadow: none;
}

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

```js
// Kodza License: free to use, client work included. Not to resell or redistribute, ported or not: https://kodza.dev/docs/#print-license
// Kodza — Password
// Shows or hides the password (keeping the caret where it was), scores it as you type (length,
// mixed case, digits, symbols), fills the meter, rolls the verdict and ticks the rules.
// The verdict is also read out to screen readers. Fires "kodza:strength" with { score } (0–4).
(() => {
  const SELECTOR = '.kodza-password';
  const reduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
  const WORDS = ['Type something', 'Too easy', 'Getting there', 'Solid', 'Very solid'];
  const RULES = {
    length: (value) => value.length >= 8,
    digit: (value) => /\d/.test(value),
    symbol: (value) => /[^A-Za-z0-9\s]/.test(value),
  };
  let uid = 0;

  const score = (value) => {
    if (!value) return 0;
    let points = 0;
    if (value.length >= 8) points++;
    if (value.length >= 14) points++;
    if (/[a-z]/.test(value) && /[A-Z]/.test(value)) points++;
    if (/\d/.test(value)) points++;
    if (/[^A-Za-z0-9\s]/.test(value)) points++;
    return Math.max(1, Math.min(4, points));
  };

  // One instance. Everything it starts is tied to `signal`, so kodza:destroy stops it all
  function mount(root, signal) {
    const input = root.querySelector('.kodza-password__input');
    const toggle = root.querySelector('.kodza-password__toggle');
    const bars = [...root.querySelectorAll('.kodza-password__meter span')];
    const word = root.querySelector('.kodza-password__word');
    const status = root.querySelector('.kodza-password__status');
    const rules = [...root.querySelectorAll('.kodza-password__rule')];
    if (!input) return;
    if (status) {
      status.id = `kodza-password-${++uid}`;
      status.setAttribute('aria-live', 'polite');
      input.setAttribute('aria-describedby', status.id);
    }
    if (word) word.replaceChildren(Object.assign(document.createElement('span'), { textContent: word.textContent.trim() }));

    // The verdict rolls up when it gets better, down when it gets worse
    const roll = (text, dir) => {
      const prev = word.lastElementChild;
      if (prev.textContent === text) return;
      const span = Object.assign(document.createElement('span'), { textContent: text });
      word.append(span);
      if (reduceMotion) return prev.remove();
      const timing = { duration: 400, easing: 'cubic-bezier(0.22, 1, 0.36, 1)' };
      prev.animate([{ transform: 'none' }, { transform: `translateY(${dir * -110}%)` }], { ...timing, fill: 'forwards' }).finished.then(() => prev.remove());
      span.animate([{ transform: `translateY(${dir * 110}%)` }, { transform: 'none' }], timing);
    };

    let last = 0;
    const update = () => {
      const value = input.value;
      const points = score(value);
      // Filling up goes left to right, emptying right to left, one step after the other
      bars.forEach((bar, i) => {
        const delay = points > last ? i - last : last - 1 - i;
        bar.style.setProperty('--d', `${Math.max(0, delay) * 60}ms`);
        bar.classList.toggle('is-on', i < points);
      });
      if (word) roll(WORDS[points], points >= last ? 1 : -1);
      rules.forEach((rule) => rule.classList.toggle('is-met', !!RULES[rule.dataset.rule]?.(value)));
      if (points !== last) root.dispatchEvent(new CustomEvent('kodza:strength', { detail: { score: points }, bubbles: true }));
      last = points;
    };
    input.addEventListener('input', update, { signal });

    toggle?.addEventListener('click', () => {
      const show = input.type === 'password';
      const { selectionStart, selectionEnd } = input;
      input.type = show ? 'text' : 'password';
      toggle.setAttribute('aria-pressed', String(show));
      toggle.setAttribute('aria-label', show ? 'Hide the password' : 'Show the password');
      input.focus();
      try {
        input.setSelectionRange(selectionStart, selectionEnd);
      } catch {
        /* some types refuse selections */
      }
    }, { signal });

    update();
  }

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