---
title: "Password Strength"
description: "Shows how strong a new password is, with a meter and a list of rules. It uses its own score, or a score you give it."
url: https://gelatinui.com/components/password-strength
markdown_url: https://gelatinui.com/components/password-strength.md
access: free
install: "npx shadcn@latest add @gelatin-ui/password-strength"
registry_item: https://gelatinui.com/r/password-strength.json
version: "2026-11-09"
index: https://gelatinui.com/llms.txt
docs_index: https://gelatinui.com/docs/llms.txt
---

# Password Strength

> Shows how strong a new password is, with a meter and a list of rules. It uses its own score, or a score you give it.

Page: https://gelatinui.com/components/password-strength

## When to use it

Best for: A strength meter and a rule list for a new password, with a built-in score or your own.

- Use it next to the input for a new password.
- Use `rules` with `PasswordStrengthRules` to list what the password must meet.
- Use `score` or `scorer` to show the result of your own check.
- Use `variant="segments"` for 5 short bars, and `size="sm"` for a tight form.

## When not to use it

- To enter the password, use a [Password Field](https://gelatinui.com/components/password-field.md).
- For another measured value, use a [Meter](https://gelatinui.com/components/meter.md).

## Notes for agents

- It is not tied to the Password Field. Pass the value of any input as `value`.
- `score` wins over `scorer`, and `scorer` wins over the built-in `scorePassword`.
- An empty `value` with no `score` has no level: an empty track and no word.
- A rule is `{ id, label, test }`. `PasswordStrengthRule` takes the `id` as its `rule` prop.
- Set `invalid` after the form tried to submit. Unmet rules then show as errors.
- `labels` holds the words for the scores 0 to 4.

## Anatomy

```text
PasswordStrength
├─ PasswordStrengthMeter (0..n)
├─ PasswordStrengthLabel (0..n)
├─ PasswordStrengthRules (0..n)
└─ PasswordStrengthRule (0..n)
```

## API reference

### PasswordStrength

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `value` | `string` | "" | The password. The parts read the rules and the built-in score from it. |
| `score` | `PasswordScore` |  | A score from your own check (0 to 4, or a zxcvbn-like `{ score }`). Wins over `scorer`. |
| `scorer` | `function` | scorePassword | Scores `value`. Default: `scorePassword` (length, kinds of characters, the rules). |
| `rules` | `readonly PasswordRule[]` | NO_PASSWORD_RULES | The requirements that `PasswordStrengthRules` lists. |
| `labels` | `PasswordStrengthLabels` | PASSWORD_STRENGTH_LABELS | The words for the scores 0 to 4. Default: Very weak, Weak, Fair, Good, Strong. |
| `invalid` | `boolean` | false | Shows unmet rules as errors (red, a cross). Set it after the form tried to submit. |
| `size` | `"default" \| "sm"` | "default" | `sm`: word and rules 12/16, icons 14. `default`: 14/20, icons 16. The track stays 4px. |
| `variant` | `"bar" \| "segments"` | "bar" | `bar`: one Meter track. `segments`: 5 short bars, `score + 1` filled. |
| `glow` | `boolean` |  | A soft halo on the fill in its level color (`glow`, `@gelatin-ui/glow`). Default: `false`. |

### PasswordStrengthMeter

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `className` | `string` |  |  |
| `glow` | `boolean` |  | A soft halo in the fill color (`glow`, `@gelatin-ui/glow`). Default: `false`. |

Also takes every prop of Base UI `Meter.Root`: https://base-ui.com/react/components/meter

### PasswordStrengthLabel

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `className` | `string` |  |  |

### PasswordStrengthRules

No props of its own: `className`, `children`, and every other prop go to the element it renders.

### PasswordStrengthRule

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `rule` | `string` |  | The `id` of the rule (in the `rules` of the root) that this row shows. |

## Styling

| Part | Slot | States | CSS variables | Tokens |
| --- | --- | --- | --- | --- |
| PasswordStrength | `password-strength` |  |  |  |
| PasswordStrengthMeter | `password-strength-meter` | `data-size` |  |  |
| PasswordStrengthLabel | `password-strength-label` | `data-size` |  |  |
| PasswordStrengthRules | `password-strength-rules` | `data-size` |  |  |
| PasswordStrengthRule | `password-strength-rule` | `data-invalid`, `data-met`, `data-size` |  | `status-colors` |

## Usage

Pass the value of any input as `value`. A rule is `{ id, label, test }`. The built-in scorer runs if you pass no `score` and no `scorer`.

```tsx title="new-password-strength.tsx"
import {
  PasswordStrength,
  PasswordStrengthMeter,
  PasswordStrengthRules,
} from "@/components/ui/password-strength";

const RULES = [
  {
    id: "length",
    label: "12 characters or more",
    test: (value: string) => {
      return value.length >= 12;
    },
  },
];

export function NewPasswordStrength({ value }: { value: string }) {
  return (
    <PasswordStrength value={value} rules={RULES}>
      <PasswordStrengthMeter />
      <PasswordStrengthRules />
    </PasswordStrength>
  );
}
```

## Compose

Rules:

- Touch targets (`touch-targets`): Give every control a hit area of at least 44 px on touch screens, even when it looks smaller.
- Group with a Frame (`group-in-frames`): Put related panels in one `Frame` with its header and footer outside the panels, and keep a plain `Card` for one block of content.
- Name every control (`label-every-control`): Give every field a visible `Label` (or a `Field`), and every icon button a `Tooltip` or an `aria-label`.
- Compose the parts (`compose-parts`): Build each item from its named parts as children, and pass your text and icons in as parts.

## Add it

```bash
npx shadcn@latest add @gelatin-ui/password-strength
```

It adds 18 registry items: 14 files, 3173 lines, and the npm packages `@base-ui/react`, `@phosphor-icons/react`, `clsx`, `motion`, `tailwind-merge`, `tailwind-variants`.

## Built on

- [Meter](https://gelatinui.com/components/meter.md)

## For AI agents

- Every item, one file: https://gelatinui.com/llms.txt
- MCP server (`search_items`, `get_item`, `get_install_plan`): https://gelatinui.com/mcp

## Related

- [Password Field](https://gelatinui.com/components/password-field.md)
- [Meter](https://gelatinui.com/components/meter.md)
- [Field](https://gelatinui.com/components/field.md)

## Accessibility

The meter is a Base UI Meter with a name, and the word beside it says the score in text.

Each rule shows its state with an icon and its text, so color is never alone.

`labels` translates the words for the scores 0 to 4.
