Components

Password Strength

A password field with a four-bar meter that fills as the password gets stronger and a checklist that ticks off each rule.

A password field with a four-bar strength meter under it. As you type, the bars fill one after another from the left and shift from red to teal. The strength word rolls in beside the label: Weak, Fair, Good or Strong. Below it, each requirement draws a check the moment it is met and erases it when it is not. The eye button draws a slash across itself when the password is shown, and blinks as it toggles. Driven by GSAP.

New tab

  • At least 10 characters(not met)
  • Upper and lower case letters(not met)
  • At least one number(not met)
  • At least one symbol(not met)

Installation

pnpm dlx shadcn@latest add @tween-ui/password-strength

Using an AI editor? Set up MCP once, then just ask for it in plain words.

Usage

app/page.tsx
app/page.tsx
import PasswordStrength from '@/components/tweenui/password-strength';
 
export default function Page() {
  return (
    <form>
      <PasswordStrength />
    </form>
  );
}

Pass your own rules to change the checklist. The meter always has four bars, so the share of rules met is scaled to them.

import PasswordStrength, { defaultRules } from '@/components/tweenui/password-strength';
 
<PasswordStrength
  rules={[...defaultRules, { label: 'No spaces', test: (value) => !/\s/.test(value) }]}
/>;

How it moves

  • Bars. Each bar scales in from the left on a 450ms power3.out ease. Bars that change are staggered 60ms apart, left to right when the score rises and right to left when it falls. Bars already filled change colour in place.
  • Word. When the level changes the word slides in from below as it rises and from above as it falls, over 350ms.
  • Checks. The circle fills with the accent and the check draws through strokeDashoffset, 100ms behind the fill. Losing a rule erases it faster.
  • Eye. The eye blinks shut and open in 300ms while its slash draws in 250ms.

Props

PropTypeDefaultDescription
labelstring"Password"Visible label and accessible name.
placeholderstring"Choose a password"Placeholder text.
namestring"password"Form field name.
autoCompletestring"new-password"Lets password managers suggest a password.
rulesPasswordRule[]defaultRulesEach rule is { label, test(value) }.
valuestring—Controlled value. Pair it with onValueChange.
defaultValuestring""Starting value when uncontrolled.
onValueChange(value, met) => void—Called on every change with the count of met rules.
classNamestring—Extra classes for the root.

The checks use --password-accent with the tick drawn in --password-on-accent. Override them with a class, e.g. [--password-accent:#e11d48]. Text, borders and the empty bars take currentColor.

Accessibility

Under prefers-reduced-motion: reduce the bars, checks, word and eye change instantly.

The input is a real <input> with a <label>, described by the strength line and the rule list. The strength line is an aria-live="polite" region, so screen readers announce "Strength: Good" as it changes. Each rule ends with a hidden "(met)" or "(not met)", and strength is always given in words, never by colour alone. A hidden password shows asterisks instead of dots. The browser still draws the mask itself: a 356-byte inline font, limited by unicode-range to the two mask characters (• and ●), turns each dot into an asterisk. So selection, the caret, scrolling, password managers and screen readers all behave exactly like a native password field. The eye is a real button labelled "Show password" or "Hide password" with aria-pressed.