Password Strength
FreeA four-step meter with a label that says how strong a password is.
npx wunderui-cli add password-strengthPlayground
Weak password
Too weak to use
Fair password
Almost there
Good password
Good enough
Strong password
Strong enough
Installation
npx wunderui-cli add password-strengthWrites the source into your project with its dependencies and, on first use, the styles - see Installation.
Then import what you need:
import { PasswordStrength } from "@/components/blocks/auth"
import type { PasswordStrengthLevel } from "@/components/blocks/auth"Then use it:
import { useState } from "react"
import { Input, PasswordStrength, getPasswordStrength } from "@wunderui/react"
export function NewPassword() {
const [password, setPassword] = useState("")
const strength = getPasswordStrength(password) // null while empty
return (
<div className="flex w-full max-w-xs flex-col gap-2">
<Input label="Password" type="password" revealable autoComplete="new-password" value={password} onChange={(event) => setPassword(event.target.value)} />
{strength && <PasswordStrength strength={strength} />}
</div>
)
}Expected result: You see an empty field. Type correct-horse and four-segment bars appear under it with three segments filled and the text Good password.
When to use
Use Password Strength for
- Quick feedback under a new-password field on a sign-up, a reset or a settings form
- One overall result of how strong a password is, in four steps
- A meter with a label that a screen reader can read, next to a field the person is typing in
Use something else for
- Password Requirement for rule-by-rule feedback that shows what is still missing
- Progress for the progress of a task or an upload
- Meter for a value inside a known range, such as disk use
Strength
Strength is weak, fair, good or strong, filling one to four segments in red, amber, blue or green. The label always names the level, so colour is never the only signal.
Weak password
Fair password
Good password
Strong password
Text
Each level has a default label, such as Good password, and you can replace it for another language or your product's words. The label is a paragraph under the bars, so a long one wraps.
Good password
Strength: good
Good password. Add a symbol or a few more characters to make it strong.
Scoring
The meter scores nothing itself: a helper returns a level from the length and kinds of characters, or null for an empty password. Show the meter only when it returns a level.
Weak password
Fair password
Good password
Strong password
Width
The meter fills the width of its parent and the four segments share it equally. Put it in a column as wide as the field above it.
Strong password
Strong password
Strong password
Behavior and motion
What the meter renders and how it reads.
- Display only
- PasswordStrength shows a level; it does not score a password, hold state or fire events. You pass the strength, and the segments and label change on the next render.
- Levels
- Strength is weak, fair, good or strong, filling one to four segments and colouring segments and label red, amber, blue and green. Unfilled segments use the border colour.
- Scoring helper
- getPasswordStrength gives one point each for 8 characters, 12 characters, mixed case, a digit and a symbol: 1 is weak, 2 fair, 3 good, 4 or 5 strong. It is a hint, not a security measure.
- Text alternative
- The label under the bars is the text alternative: it says the level in words and is always shown, so the meter never rests on colour alone. The bars have no role, so a screen reader reads the label.
- Announcing changes
- The wrapper is a polite live region, so a label change is spoken when the person pauses. Render the meter from the first key on and keep it mounted, or some screen readers stay silent.
- Label
- The label replaces the default text for the level. A long text wraps under the bars, and nothing is cut.
- Width
- The wrapper fills its parent and the four segments share the width equally. At 160 px the bars are about 37 px wide and the label still fits on one line.
- Sample values
- Use obviously made-up passwords in examples and tests, such as correct-horse. The demos run on local state and send nothing.
- Dark mode
- It uses theme tokens for the segments and text, so it follows the theme.
- Motion
- None. The segments and colour change at once when the level changes; nothing fades or slides.
- Reduced motion
- There is no motion, so reduced motion changes nothing.
Anatomy
The figure shows the meter at the Good level: three of four segments filled. In the DOM the wrapper holds the row of segments and then the label.
Good password
- 1data-slot="password-strength"
A column with 6 px between the segments and the label, announced politely. It fills the width of its parent, holds no state and tests nothing: you pass the level.
- 2
A row of four bars, 4 px high with 4 px between them, sharing the width equally. They carry no text and no role: they are drawn, not read.
- 3
One bar: the first one to four are filled with the colour of the level and the rest use the border colour. Weak fills 1, fair 2, good 3, strong 4.
- 4
The text under the bars in 12 px type, in the colour of the level: Weak password, Fair password, Good password or Strong password, or your own label. It is always shown.
Best practices
- Do
Get the level from getPasswordStrength and render the meter only when it returns one (null for an empty password). Keep it mounted while the person types, so level changes are announced.
- Do
Leave the label on: it says the level in words, so colour is never the only signal, and a screen reader reads the label, not the bars. Pass your own label for other wording or another language.
- Do
Reserve the height of the meter and put a hint in it until the first key, as in the sign-up example, so the form does not jump when the meter appears.
- Do
Put the meter in a column as wide as the field above it. It fills the width of its parent.
- Don’t
Don't treat the helper as your password policy: it scores only length and character kinds, so Password1! scores strong. Enforce your real rules on the server and show them with Password Requirement.
- Don’t
Don't show a level for a password that is not typed. An empty field has no strength, and a weak bar for an empty field reads as an error.
- Don’t
Don't use real passwords in examples, tests or screenshots; use obviously made-up strings such as correct-horse. The demos keep them in local state and send nothing.
API reference
One table: PasswordStrength is a plain component, so it lists every prop. It does not pass other props on to its element.
A column with 6 px between the segments and the label, announced politely. It fills the width of its parent, holds no state and tests nothing: you pass the level.
| Prop | Type | Default | Description |
|---|---|---|---|
| strength required | "weak" | "fair" | "good" | "strong" | — | The level to show. Required. It fills one to four segments and sets the colour. Get it from , which returns for an empty password. |
| label | string | — | The text under the bars. Defaults to the name of the level followed by . Pass your own words or another language; a long text wraps. |
| className | string | — | Extra classes for the wrapper, merged after its own. Use them for a margin or a maximum width. |
Notes for AI
Give your coding assistant the Markdown reference instead of screenshots.
get_component("password-strength")npx wunderui-cli add password-strengthThe full library index for assistants is at /llms.txt.