Pure TailwindMIT licensed

Tailwind Password Strength Meter

A live strength bar graded from native constraints alone — minlength and a character-class pattern, read through group-has-[…] into four bar widths. No scoring library, no script.

Live Demo
Plain CSSTailwind v4
Try it

Untitled UI Pro: 5,000+ React + Tailwind CSS v4 components · from $349 one-time

Untitled UI React · Affiliate link

Get Untitled UI Pro

The code

<div class="tif-09 grid min-h-svh w-full place-items-center bg-tif09-bg px-6 py-14 font-tif09-sans" aria-label="Password strength meter demo">
  <label class="group grid w-full max-w-70 gap-1.5 text-[11px] text-tif09-mut">
    <span class="font-semibold">Password</span>
    <input type="password" name="tif09-pw" autocomplete="new-password" placeholder="At least 12 characters" minlength="12" pattern="(?=.*\d)(?=.*[^A-Za-z0-9]).{12,}" required aria-describedby="tif09-hint"
      class="w-full rounded-lg border border-white/10 bg-tif09-field px-3.5 py-2.5 text-sm text-tif09-ink outline-none transition-colors duration-200 focus:border-tif09-acc">
    <span class="relative h-1 overflow-hidden rounded-full bg-white/8" aria-hidden="true">
      <span class="absolute inset-y-0 left-0 w-0 rounded-full bg-linear-to-r from-tif09-bad via-tif09-warn to-tif09-ok transition-[width] duration-300 ease-out group-has-[input:not(:placeholder-shown):invalid]:w-[30%] group-has-[input:not(:placeholder-shown):valid]:w-[65%] group-has-[input:focus:valid]:w-full motion-reduce:transition-none"></span>
    </span>
    <span id="tif09-hint" class="text-[10.5px] text-tif09-mut">Use 12+ characters with letters, numbers, and a symbol.</span>
  </label>
</div>
@import "tailwindcss";

@theme {
  --color-tif09-bg: #12121a;
  --color-tif09-bg: oklch(0.19 0.015 285);
  --color-tif09-field: #1a1a22;
  --color-tif09-field: oklch(0.23 0.015 285);
  --color-tif09-ink: #f0eeff;
  --color-tif09-ink: oklch(0.95 0.02 290);
  --color-tif09-mut: #b8b6d4;
  --color-tif09-mut: oklch(0.77 0.03 290);
  --color-tif09-acc: #c084fc;
  --color-tif09-acc: oklch(0.75 0.17 305);
  --color-tif09-bad: #ef4444;
  --color-tif09-bad: oklch(0.63 0.22 27);
  --color-tif09-warn: #f59e0b;
  --color-tif09-warn: oklch(0.76 0.16 70);
  --color-tif09-ok: #22c55e;
  --color-tif09-ok: oklch(0.73 0.19 145);
  --font-tif09-sans: 'Plus Jakarta Sans', system-ui, sans-serif;
}

.tif-09 {
  width: 100%;
}

.tif-09 ::selection {
  background: var(--color-tif09-acc);
  color: #12121a;
}

Setup — do this once per project

Skip this if your project already runs Tailwind v4.

1Load Tailwind
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>

Compiles in the browser — perfect for a CodePen or a quick test, not for production.

2Add the stylesheetRequiredthe @theme block is what makes the custom utilities exist
@import "tailwindcss";

@theme {
  --color-tif09-bg: #12121a;
  --color-tif09-bg: oklch(0.19 0.015 285);
  --color-tif09-field: #1a1a22;
  --color-tif09-field: oklch(0.23 0.015 285);
  --color-tif09-ink: #f0eeff;
  --color-tif09-ink: oklch(0.95 0.02 290);
  --color-tif09-mut: #b8b6d4;
  --color-tif09-mut: oklch(0.77 0.03 290);
  --color-tif09-acc: #c084fc;
  --color-tif09-acc: oklch(0.75 0.17 305);
  --color-tif09-bad: #ef4444;
  --color-tif09-bad: oklch(0.63 0.22 27);
  --color-tif09-warn: #f59e0b;
  --color-tif09-warn: oklch(0.76 0.16 70);
  --color-tif09-ok: #22c55e;
  --color-tif09-ok: oklch(0.73 0.19 145);
  --font-tif09-sans: 'Plus Jakarta Sans', system-ui, sans-serif;
}

.tif-09 {
  width: 100%;
}

.tif-09 ::selection {
  background: var(--color-tif09-acc);
  color: #12121a;
}
3Fonts used by this demooptional — skip if you have your own type stack
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700&display=swap">

What changed in the port

Which parts became utilities, which stayed CSS, and why.

  • Bug fixed. The CSS original's demo 09 is two stylesheets stacked: a strength meter, then a password-toggle sheet redefining .if-09, .if-09-label and .if-09 input with markup that does not exist in the demo. This entry is the strength meter alone; the toggle is entry 27.
  • The minlength=&quot;6&quot; that contradicted a &quot;12+ characters&quot; hint is now minlength=&quot;12&quot; with a matching pattern, so the bar and the copy agree.
  • aria-describedby added: the gradient says nothing to a screen reader, the hint does.
Paste this into ChatGPT, Claude, Cursor, or any coding assistant. The block below is pre-framed with everything the AI needs to integrate this demo into your project — markup, styles, scoping notes, and the source URL. Hit Copy and paste straight into your chat.
Here's a working CSS demo from CodeFronts. Use it as-is or adapt to your framework. All classes are scoped under a unique prefix so the code won't collide with your existing styles. MIT licensed.
Demo: Tailwind Password Strength Meter
Source: https://codefronts.com/components/tailwind-css-input-fields/tailwind-password-strength-meter/

A live strength bar graded from native constraints alone — minlength and a character-class pattern, read through group-has-[…] into four bar widths. No scoring library, no script.
## HTML
```html
<div class="tif-09 grid min-h-svh w-full place-items-center bg-tif09-bg px-6 py-14 font-tif09-sans" aria-label="Password strength meter demo">
  <label class="group grid w-full max-w-70 gap-1.5 text-[11px] text-tif09-mut">
    <span class="font-semibold">Password</span>
    <input type="password" name="tif09-pw" autocomplete="new-password" placeholder="At least 12 characters" minlength="12" pattern="(?=.*\d)(?=.*[^A-Za-z0-9]).{12,}" required aria-describedby="tif09-hint"
      class="w-full rounded-lg border border-white/10 bg-tif09-field px-3.5 py-2.5 text-sm text-tif09-ink outline-none transition-colors duration-200 focus:border-tif09-acc">
    <span class="relative h-1 overflow-hidden rounded-full bg-white/8" aria-hidden="true">
      <span class="absolute inset-y-0 left-0 w-0 rounded-full bg-linear-to-r from-tif09-bad via-tif09-warn to-tif09-ok transition-[width] duration-300 ease-out group-has-[input:not(:placeholder-shown):invalid]:w-[30%] group-has-[input:not(:placeholder-shown):valid]:w-[65%] group-has-[input:focus:valid]:w-full motion-reduce:transition-none"></span>
    </span>
    <span id="tif09-hint" class="text-[10.5px] text-tif09-mut">Use 12+ characters with letters, numbers, and a symbol.</span>
  </label>
</div>
```
## CSS
```css
@import "tailwindcss";

@theme {
  --color-tif09-bg: #12121a;
  --color-tif09-bg: oklch(0.19 0.015 285);
  --color-tif09-field: #1a1a22;
  --color-tif09-field: oklch(0.23 0.015 285);
  --color-tif09-ink: #f0eeff;
  --color-tif09-ink: oklch(0.95 0.02 290);
  --color-tif09-mut: #b8b6d4;
  --color-tif09-mut: oklch(0.77 0.03 290);
  --color-tif09-acc: #c084fc;
  --color-tif09-acc: oklch(0.75 0.17 305);
  --color-tif09-bad: #ef4444;
  --color-tif09-bad: oklch(0.63 0.22 27);
  --color-tif09-warn: #f59e0b;
  --color-tif09-warn: oklch(0.76 0.16 70);
  --color-tif09-ok: #22c55e;
  --color-tif09-ok: oklch(0.73 0.19 145);
  --font-tif09-sans: 'Plus Jakarta Sans', system-ui, sans-serif;
}

.tif-09 {
  width: 100%;
}

.tif-09 ::selection {
  background: var(--color-tif09-acc);
  color: #12121a;
}
```

How this works

The grade is four widths. Each is a variant on the fill, and only one can match at a time because the selectors are mutually exclusive:

class="w-0 group-has-[input:not(:placeholder-shown):invalid]:w-[30%]
  group-has-[input:valid]:w-[65%] group-has-[input:focus:valid]:w-full"

Native constraints are the scorer. minlength="8" plus a pattern demanding a digit and a symbol is genuinely most of what a strength meter measures. What it cannot measure is entropy or dictionary hits — for that you need zxcvbn and a script, and this is honestly not that.

Make it yours

  • Grade harder: tighten the pattern — (?=.*\d)(?=.*[!@#$%^&*]) is already in the markup; add length or case classes.
  • Bands: the four width values. 30/65/100 is a feel, not a law.
  • Colours: the three gradient stops in @theme.
  • Ease: duration-300 on the fill; faster reads as twitchy while typing.

Gotchas — read before shipping

  • This grades form constraints, not password quality. It cannot know that Passw0rd! is terrible.
  • The placeholder must be non-empty for the empty-state rule to fire.
  • A visual bar is invisible to screen readers — the aria-describedby hint is the actual accessible feedback, not the gradient.

Browser support

ChromeSafariFirefoxEdge
111+16.4+128+111+

:has() is Baseline; without it the bar stays empty and the password field works normally.

Techniques used in this demo

Utilitiesfirst-class utility or variant

Theme tokensset in @theme, used by a utility

Search CodeFronts

Loading…