Xzero UI
Pro library

Password strength

Show how strong a new password is while it is typed.

$ pnpm dlx shadcn@4.23.0 add @xzero-ui/password-strength
Live · keyboard ready

When to use

When not to use

Installation

Register both Xzero UI namespaces in your project's components.json:

{
  "registries": {
    "@xzero-ui": "https://mcp.xzero.co.uk/r/{name}.json",
    "@xzero-ui-pro": "https://mcp.xzero.co.uk/r/pro/{name}.json"
  }
}
npx shadcn@4.23.0 add @xzero-ui/password-strength

Install xzero-foundation once, and import @/components/xzero/foundation.css in your app root. No Xzero token is used by this snapshot. For sample portraits, photos, fonts, or logos, download https://mcp.xzero.co.uk/install-assets.mjs and run node xzero-install-assets.mjs <receiving-project>.

Usage

import { PasswordStrength } from "@/components/xzero/password-strength/password-strength";

export function NewPasswordField() {
  const [strong, setStrong] = useState(false);
  return (
    <PasswordStrength
      label="New password"
      name="password"
      autoComplete="new-password"
      onValueChange={(_, strength) => setStrong(strength.level >= 3)}
    />
  );
}

Examples

Gate submit on strength

const [level, setLevel] = useState(0);

<PasswordStrength
  label="New password"
  name="password"
  autoComplete="new-password"
  onValueChange={(_, strength) => setLevel(strength.level)}
/>
<Button type="submit" disabled={level < 3}>Create account</Button>

Translated, with your own length policy

import { PasswordStrength, createPasswordRules } from "@/components/xzero/password-strength/password-strength";

const rules = createPasswordRules({
  minLength: 10,
  labels: {
    length: min => `Mindestens ${min} Zeichen`,
    case: "Gross- und Kleinbuchstaben",
    number: "Mindestens eine Zahl",
    symbol: "Mindestens ein Sonderzeichen",
  },
});

export function NewPassword() {
  return (
    <PasswordStrength
      label="Neues Passwort"
      rules={rules}
      shortLength={10}
      messages={{
        levels: { tooShort: "Zu kurz", weak: "Schwach", fair: "Mittel", good: "Gut", strong: "Stark" },
        showPassword: "Passwort anzeigen",
        meterLabel: "Passwortstärke",
        noPassword: "Noch kein Passwort",
        rulesLabel: "Passwortanforderungen",
        ruleMet: ", erfüllt",
        ruleNotMet: ", nicht erfüllt",
        remainingPrefix: "noch",
        remainingSuffix: "",
        summary: ({ label, met, total }) => `Stärke: ${label}. ${met} von ${total} Anforderungen erfüllt.`,
      }}
    />
  );
}

API reference

PasswordStrength

A new-password field with a four-segment meter, rule checklist, and a morphing strength word.

PropTypeDefaultDescription
label (required)string–Visible label tied to the input.
valuestring–Controlled password.
defaultValuestring""Initial value when uncontrolled.
onValueChange(value: string, strength: PasswordStrengthResult) => void–Called on every change with the value and its { level, label, met } score.
rulesPasswordRule[]defaultPasswordRules{ id, label, test, remaining? } rules. Strength is the share met across four steps.
errorstring–Error copy; sets aria-invalid and shakes the field once per new error.
revealedboolean–Controlled show or hide state.
onRevealedChange(revealed: boolean) => void–Called when the reveal toggle is pressed.
messagesPasswordStrengthMessagesInputdefaultPasswordStrengthMessagesEvery built-in string, for translation: levels { tooShort, weak, fair, good, strong }, showPassword, meterLabel, noPassword, rulesLabel, ruleMet, ruleNotMet, remainingPrefix, remainingSuffix, and summary({ label, met, total }). Pass only what you change; the rest stay English.
shortLengthnumber8Below this many characters the meter holds at its first step and reads the tooShort word.
countCharacters(password: string) => numbercountCodePointsHow shortLength counts characters. Code points by default (an emoji counts once); pass password => password.length to match a policy that counts UTF-16 units.
...propsOmit<InputHTMLAttributes<HTMLInputElement>, "type" | "value" | "defaultValue" | "children">–Forwarded to the input, including ref, name, autoComplete, and onChange.

Keyboard interactions

KeysAction
Enter / SpaceOn the reveal button, shows or hides the password.

Accessibility

Motion

Responsive behavior

Performance

Notes for AI

Also in text fields

Guidance for AI tools

Password strength: Show how strong a new password is while it is typed. Follow the declared prop types and do not invent props. Keep keyboard access, reduced motion support, and both light and dark themes intact when adapting it.

Full library index: https://ui.xzero.co.uk/llms.txt

Browse all components