Password Strength

A password input with an animated strength meter and requirements checklist.

@spectrumui/password-strength

Create account

Password strength: Too weak
  • At least 8 characters
  • One uppercase letter
  • One number
  • One symbol

Type a password — the meter fills and requirements check off as you go

Installation

Login to view commandCreate a free account to access the install command

Usage

import { PasswordStrengthInput } from "@/components/spectrumui/password-strength"
<PasswordStrengthInput onValueChange={(value) => console.log(value)} />

API Reference

PasswordStrengthInput

Renders a password input with a visibility toggle, a strength meter announced via a polite live region, and a requirements checklist. Pass value to control it from outside, or defaultValue to let it manage its own state. Strength is scored against rules, an array of PasswordRule objects of the shape { label: string; test: (value: string) => boolean }. The exported DEFAULT_RULES check for at least 8 characters, one uppercase letter, one number and one symbol.

PropTypeDefaultDescription
valuestring-Controlled value. Leave undefined for uncontrolled usage
defaultValuestring""Initial value when uncontrolled
onValueChange(value: string) => void-Fires with the next value on every keystroke
rulesPasswordRule[]DEFAULT_RULESRules scored by the meter and listed in the checklist
showChecklistbooleantrueRender the requirements checklist
showMeterbooleantrueRender the strength meter and label
placeholderstring"Enter password"Placeholder of the input
idstring-Id of the input element
namestring-Name of the input element
autoCompletestring"new-password"Autocomplete hint of the input
disabledbooleanfalseDisables the input and the visibility toggle
onFocusReact.FocusEventHandler<HTMLInputElement>-Forwarded to the input element
onBlurReact.FocusEventHandler<HTMLInputElement>-Forwarded to the input element
classNamestring-Additional classes merged onto the wrapper element

Examples

Custom rules and meter only

Custom rules
Password strength: Too weak
  • At least 8 characters
  • One uppercase letter
  • One number
  • One symbol
  • No spaces
Meter only
Password strength: Too weak