Password Strength V2
A 4 px bar under the password field, and nothing else: a third in red, two thirds in orange, full in green. It rates the length and variety of characters, not real security.
Updated
This effect is part of Effect.Labs — 846 vanilla effects, some free, some premium. Forms has 21 effects, including 2 free. Explore the category →
3 usage examples



How it works
On every keystroke the script counts five points of shape: 6 characters or more, 10 or more, a capital from A to Z, a digit, a sign that is neither letter nor digit (an accented letter counts as a sign here). With 0 to 2 points the bar stops at 33% in red, with 3 points at 66% in orange, with 4 or 5 it is full and green. Empty field: empty bar.
The result lives in one attribute, data-strength on .pwsb-group (empty, weak, medium, strong). The CSS derives width and colour from it and the bar slides in 0.3 s; your code can read that same attribute to grey out a button, as in the phone example.
No word is displayed. Under the field the effect takes only 12 px (34 px for the version with text). The level in words still exists, in a region hidden on screen and read by screen readers; its three phrases are set in the hidden .pwsb-words block.
What the bar does not know: whether the password is on a list of stolen passwords, whether it follows a keyboard run, whether it is already used elsewhere. "Qwerty1!", eight characters, fills it green; a twenty-six-character sentence, all lowercase with spaces, stops at orange. It is a guide while typing. The real check happens on your server.
Accessibility
- What is announced: the hidden
.pwsb-statusregion isaria-live="polite"and is only rewritten when the level changes (3 announcements for 12 keystrokes, measured). Its texts say what is measured, "Length and variety: low", "medium", "good", not "strong password". - Field description: the script adds that region to
aria-describedbywithout removing what you put there. A rule written under the field and linked by itsidis therefore still read on focus. - Sighted users: they only get the bar. Its length changes with the colour (a third, two thirds, full), so colour is not the only carrier; but nothing says which criterion is missing. Keep a visible rule sentence next to it.
- Label: "Password" sits in a
<label>hidden on screen; the field's grey text is a hint and goes away on typing.autocomplete="new-password"lets password managers offer their own. - System-imposed colours: in high-contrast mode the bar gets an outline and a system colour.
- Reduced motion: the bar changes length without sliding; only its colour fades in 0.2 s.
Browser compatibility
2.3 KB of dependency-free JavaScript. Floor set by NodeList.forEach: Chrome 51, Firefox 50, Safari 10 (@mdn/browser-compat-data). Checked on 04/12/2026 in Chromium 149, Firefox 151 and WebKit 26.5: two fields on the page, each with its own status region and id; typing in the second leaves the first untouched; value already present on load; form reset; an existing aria-describedby kept; 390 px touch screen; reduced motion; forced colours (Chromium and Firefox).
With JavaScript off, the field takes input and submits normally; the bar stays empty and nothing is announced (measured).
The code
HTML structure to paste into your page (the CSS + JS come with your purchase):
<div class="fx-0297-root">
<div class="pwsb-group" data-strength="empty">
<label class="pwsb-field">
<span class="pwsb-sr">Password</span>
<input class="pwsb-input" type="password" name="password" autocomplete="new-password" placeholder="Enter a password">
</label>
<div class="pwsb-meter" aria-hidden="true">
<div class="pwsb-fill"></div>
</div>
<span class="pwsb-sr pwsb-status" aria-live="polite"></span>
<span class="pwsb-words" hidden>
<span data-level="weak">Length and variety: low</span>
<span data-level="medium">Length and variety: medium</span>
<span data-level="strong">Length and variety: good</span>
</span>
</div>
</div>
One-time payment, no subscription — the code is yours forever
Customize
Options passed to the API or data-* attributes:
| Option / property | Default | Effect |
|---|---|---|
Level colours (CSS — --pwsb-weak, --pwsb-medium, --pwsb-strong) |
#ef4444 · #f59e0b · #10b981 | On a light background darken them (#dc2626, #d97706, #059669): the bar is thin, it needs contrast. |
Bar (CSS — --pwsb-bar-height, --pwsb-track) |
4px · white at 10% | Thickness, and colour of the empty track. 6 px reads better on a phone. |
Announced words (HTML — .pwsb-words) |
Length and variety: low · medium · good | Read by the script at each change of level: translate them here. Avoid wording that promises security. |
Field (CSS — --pwsb-field, --pwsb-border, --pwsb-focus, --pwsb-text) |
white at 5% · white at 10% · #6366f1 · #fff | Fill, frame, frame on focus, text. |
Sizes (CSS — --pwsb-width, --pwsb-font-size) |
280px · 1rem | The width is a ceiling; 100% fills the parent. |
Demo backdrop (CSS — --pwsb-bg, --pwsb-min-height) |
#0a0a0f · 300px | In a form: --pwsb-bg:transparent; --pwsb-min-height:0. |
Scoring (JS — score() and the thresholds in update()) |
5 points; red ≤ 2, orange = 3, green ≥ 4 | To keep green for passwords of 10 characters, return 3 at most while pw.length < 10. |
FAQ
score() and check on the server; the effect's display does not change.aria-describedby="rule" in your HTML, the field carries aria-describedby="rule pwsb-status-1" after start-up: your rule is read first, the level next. The status region's id is created by the script, one per instance.