Password strength
Provide visual feedback on password strength with segmented meters or progress bars that update as users type.
Overview
Strength meters help users create secure passwords by providing real-time feedback on password complexity. Bootstrap’s strength component offers:
- Segmented meter: Four segments that fill based on strength level
- Progress bar variant: A single bar that grows with strength
- Text feedback: Optional text messages for each strength level
- Customizable scoring: Configure minimum length and scoring criteria
- Minimal JavaScript: Lightweight component following Bootstrap patterns
Examples
Segmented
The default strength meter uses four segments that fill progressively as password strength increases. The PasswordStrength component enables JavaScript behavior automatically.
<div>
<FormLabel htmlFor="password1">
Password
</FormLabel>
<FormControl
id="password1"
placeholder="Enter password"
type="password"
/>
<PasswordStrength
input="#password1"
showText={false}
/>
</div>With text feedback
PasswordStrength displays the strength message by default. Set showText={false} to hide it.
<div>
<FormLabel htmlFor="password2">
Password
</FormLabel>
<FormControl
id="password2"
placeholder="Enter password"
type="password"
/>
<PasswordStrength
input="#password2"
showText
/>
</div>Progress bar
Set variant="bar" on PasswordStrength for a single progress bar that grows with password strength.
<div>
<FormLabel htmlFor="password3">
Password
</FormLabel>
<FormControl
id="password3"
placeholder="Enter password"
type="password"
/>
<PasswordStrength
input="#password3"
showText={false}
variant="bar"
/>
</div>Static segmented
You can use the component without JavaScript for static displays by passing the strength prop.
<Stack
className="fg-3"
gap={3}
>
<div>
<div>
Weak
</div>
<PasswordStrength
showText={false}
strength="weak"
/>
</div>
<div>
<div>
Fair
</div>
<PasswordStrength
showText={false}
strength="fair"
/>
</div>
<div>
<div>
Good
</div>
<PasswordStrength
showText={false}
strength="good"
/>
</div>
<div>
<div>
Strong
</div>
<PasswordStrength
showText={false}
strength="strong"
/>
</div>
</Stack>Static progress bar
<Stack
className="fg-3"
gap={3}
>
<div>
<div>
Weak
</div>
<PasswordStrength
showText={false}
strength="weak"
variant="bar"
/>
</div>
<div>
<div>
Fair
</div>
<PasswordStrength
showText={false}
strength="fair"
variant="bar"
/>
</div>
<div>
<div>
Good
</div>
<PasswordStrength
showText={false}
strength="good"
variant="bar"
/>
</div>
<div>
<div>
Strong
</div>
<PasswordStrength
showText={false}
strength="strong"
variant="bar"
/>
</div>
</Stack>Strength criteria
The default scoring algorithm evaluates passwords based on:
| Criteria | Points |
|---|---|
| Meets minimum length (8 characters) | +1 |
| 4+ characters over minimum | +1 |
| Contains lowercase letters | +1 |
| Contains uppercase letters | +1 |
| Contains numbers | +1 |
| Contains special characters | +1 |
| Multiple special characters | +1 |
| 16+ characters | +1 |
| Level | Points |
|---|---|
| Weak | 1-2 |
| Fair | 3-4 |
| Good | 5-6 |
| Strong | 7-8 |
Usage
PasswordStrength binds to the password field through input, or discovers a sibling input. Pass scoring options as props. Use strength for a static meter and showText for feedback.
Options
| Name | Type | Default | Description |
|---|---|---|---|
input | string | element | null | Selector or element for the password input. If not provided, looks for input[type="password"] in the parent. |
minLength | number | 8 | Minimum password length for first strength point. |
messages | object | {weak, fair, good, strong} | Custom messages for each strength level. |
weights | object | See below | Point values for each scoring criterion. Set to 0 to disable a criterion. |
thresholds | array | [2, 4, 6] | Score boundaries for strength levels: [weak, fair, good]. Scores above the last value are "strong". |
scorer | function | null | Custom scoring function (password) => number. Overrides built-in scoring when provided. |
Default weights
{
minLength: 1, // Meets minimum length
extraLength: 1, // 4+ characters over minimum
lowercase: 1, // Contains lowercase letters
uppercase: 1, // Contains uppercase letters
numbers: 1, // Contains numbers
special: 1, // Contains special characters
multipleSpecial: 1, // Multiple special characters
longPassword: 1 // 16+ characters
}
Custom weights
<PasswordStrength weights={{ uppercase: 0, special: 2 }} thresholds={[3, 5, 7]} />
Custom scorer
<PasswordStrength
scorer={password => Number(password.length >= 12) * 4 + Number(/[!@#$%]/.test(password)) * 4}
thresholds={[2, 4, 6]}
/>
CSS-only usage
For simple cases or server-rendered content, you can use the component without JavaScript by passing the strength prop.
<PasswordStrength strength="good" />
Accessibility
- The strength meter is decorative feedback and should be used alongside clear password requirements text
- Consider using
aria-describedbyto associate the password input with requirement text - Screen reader users benefit from the text feedback option which announces strength changes
CSS
Variables
.example {
--bs-strength-height: 0.375rem;
--bs-strength-gap: 0.25rem;
--bs-strength-margin-top: 0.25rem;
--bs-strength-border-radius: var(--bs-radius-pill);
--bs-strength-bg: var(--bs-bg-2);
--bs-strength-color: var(--bs-bg-2);
--bs-strength-weak-color: var(--bs-danger-bg);
--bs-strength-fair-color: var(--bs-warning-bg);
--bs-strength-good-color: var(--bs-info-bg);
--bs-strength-strong-color: var(--bs-success-bg);
}