Password Strength Meter
A password field with a show toggle, a four-step meter and a plain-language tip; length matters more than symbols.
AI prompt
Clean UI mockup of a sign-up form password field with a show eye icon at the right, below it a four-segment strength meter with two segments filled in orange and the label Fair, a hint line reading Add another word to make it stronger, and a small checklist with a green check for at least 12 characters and a grey circle for not a common password, light theme, flat modern style. Negative: heavy shadows, clutter, text errors, device frames. Reduced motion: static design.About this pattern
Definition
A strength meter gives quick feedback as someone types. The most helpful rules are length and avoiding common passwords, not forced symbols. A good meter says what to do next, such as add another word, and never claims the password is safe; it only estimates how hard it is to guess.
Purpose & UX principles
- Score mostly on length; a long passphrase beats a short complex one.
- Mark very common passwords as weak at once.
- Show the meter with text, not colour alone, and announce changes politely.
- Provide a Show toggle so people can check what they typed, and allow pasting from password managers.
Interaction states
- Type a password; try a common one, a short one and a long passphrase.
Motion specification
- The meter fills over 200ms.
- Reduced motion: no transition.
Responsive behaviour
- Do not send the password anywhere to measure it in the browser demo.
- A client-side meter is only a hint; the server must still apply real checks.
Code
<div class="bx"><label class="fl" for="pw">Password</label><div class="inp"><input id="pw" type="password" autocomplete="off" spellcheck="false" aria-describedby="hint"><button type="button" class="mini" id="sh" aria-pressed="false">Show</button></div><div class="mt" aria-hidden="true"><i></i><i></i><i></i><i></i></div><p class="st" id="st" role="status">Start typing.</p><ul class="ck" id="ck"></ul><p class="out" id="hint">This demo checks nothing on a server and stores nothing.</p></div>:root{--bg:#F1F1EF;--surface:#fff;--surface-2:#F7F7F5;--line:#E0E0DC;--text:#171717;--muted:#6f6f6f;--accent:#171717;--accent-ink:#fff;--danger:#d92d20}
*{box-sizing:border-box;margin:0}
button{font:inherit;color:inherit;background:none;border:0;padding:0;cursor:pointer}a{color:inherit;text-decoration:none}ul,ol,p,h4{margin:0;padding:0}.sr-only{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
.pre{display:flex;gap:5px;flex-wrap:wrap}.pre button{height:28px;padding:0 11px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font-size:11px;cursor:pointer}
.pre button[aria-pressed=true]{background:var(--accent);color:var(--accent-ink);border-color:var(--accent)}
.bx{width:min(330px,100%);display:grid;gap:9px}.rw{display:grid;gap:3px;font-size:11.5px;color:var(--muted)}.rw b{color:var(--text);font-weight:600}input[type=range]{width:100%;accent-color:#171717}
.out{font-size:12px;color:var(--muted);line-height:1.4}.out b{color:var(--text)}
button:focus-visible,input:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
.fl{font-size:12px;font-weight:600}.inp{display:flex;gap:6px;margin:4px 0 8px}.inp input{flex:1;min-width:0;height:36px;border:1px solid var(--line);border-radius:10px;padding:0 12px;font:inherit;font-size:14px;background:var(--surface);color:var(--text)}.mt{display:grid;grid-template-columns:repeat(4,1fr);gap:4px}.mt i{height:6px;border-radius:3px;background:#e6e6e2;transition:background .2s}.st{margin:6px 0;font-size:12.5px;font-weight:600}.ck{list-style:none;display:grid;gap:3px;font-size:12px;color:var(--muted)}.ck li::before{content:"\25CB ";}.ck li.ok{color:#1f7a45}.ck li.ok::before{content:"\2713 ";}.out{font-size:11.5px;color:var(--muted);margin:6px 0 0}.mini{height:30px;padding:0 14px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font-size:12px;font-weight:600;cursor:pointer}.mini:disabled{opacity:.4;cursor:default}@media (prefers-reduced-motion:reduce){.mt i{transition:none}}
@media (prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}}const pw=document.getElementById('pw'),sh=document.getElementById('sh'),segs=[...document.querySelectorAll('.mt i')],st=document.getElementById('st'),ck=document.getElementById('ck');const COMMON=['password','123456','12345678','qwerty','letmein','111111','iloveyou','admin','welcome','abc123','password1','123456789'];const COL=['#d92d20','#e8832d','#d6b300','#1f9d55'],TX=['Very weak','Weak','Fair','Strong'];
function score(v){if(!v)return -1;if(COMMON.includes(v.toLowerCase()))return 0;let s=0;const L=v.length;if(L>=8)s++;if(L>=12)s++;if(L>=16)s++;const cls=[/[a-z]/,/[A-Z]/,/\d/,/[^A-Za-z0-9]/].filter(r=>r.test(v)).length;if(cls>=3&&L>=10)s++;if(/^(.)\1+$/.test(v)||/^(0123|1234|abcd|qwer)/i.test(v))s=Math.min(s,1);if(L<8)s=Math.min(s,1);return Math.max(0,Math.min(3,s-(L<8?0:0)-(s>3?1:0)));}
function up(){const v=pw.value,s=score(v);segs.forEach((e,i)=>e.style.background=s>=0&&i<=s?COL[s]:'#e6e6e2');
st.textContent=s<0?'Start typing.':TX[s]+(s===0&&COMMON.includes(v.toLowerCase())?' \u2013 this is a very common password.':s<3?' \u2013 add another word or a few more characters.':' \u2013 a long password is hard to guess.');
const R=[['At least 12 characters',v.length>=12],['Not a very common password',v&&!COMMON.includes(v.toLowerCase())],['Mixes words, numbers or symbols',/[a-z]/i.test(v)&&(/\d/.test(v)||/[^A-Za-z0-9]/.test(v)||/\s|-/.test(v))]];ck.innerHTML=R.map(r=>'<li class="'+(r[1]?'ok':'')+'">'+r[0]+'</li>').join('');}
pw.addEventListener('input',up);sh.addEventListener('click',()=>{const on=pw.type==='password';pw.type=on?'text':'password';sh.textContent=on?'Hide':'Show';sh.setAttribute('aria-pressed',String(on));});up();One complete HTML file. Save it and open it in a browser.
<!doctype html>
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Password Strength Meter — demo</title>
<style>
:root{--bg:#F1F1EF;--surface:#fff;--surface-2:#F7F7F5;--line:#E0E0DC;--text:#171717;--muted:#6f6f6f;--accent:#171717;--accent-ink:#fff;--danger:#d92d20}
*{box-sizing:border-box;margin:0}
html,body{height:100%}body{background:var(--bg);color:var(--text);font:15px/1.5 -apple-system,BlinkMacSystemFont,'Segoe UI',Inter,Roboto,sans-serif;-webkit-font-smoothing:antialiased}.stage{min-height:100%;display:grid;place-items:center;padding:24px}button,input,select,textarea{font-family:inherit}@media (prefers-reduced-motion:reduce){html{scroll-behavior:auto}}
button{font:inherit;color:inherit;background:none;border:0;padding:0;cursor:pointer}a{color:inherit;text-decoration:none}ul,ol,p,h4{margin:0;padding:0}.sr-only{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
.pre{display:flex;gap:5px;flex-wrap:wrap}.pre button{height:28px;padding:0 11px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font-size:11px;cursor:pointer}
.pre button[aria-pressed=true]{background:var(--accent);color:var(--accent-ink);border-color:var(--accent)}
.bx{width:min(330px,100%);display:grid;gap:9px}.rw{display:grid;gap:3px;font-size:11.5px;color:var(--muted)}.rw b{color:var(--text);font-weight:600}input[type=range]{width:100%;accent-color:#171717}
.out{font-size:12px;color:var(--muted);line-height:1.4}.out b{color:var(--text)}
button:focus-visible,input:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
.fl{font-size:12px;font-weight:600}.inp{display:flex;gap:6px;margin:4px 0 8px}.inp input{flex:1;min-width:0;height:36px;border:1px solid var(--line);border-radius:10px;padding:0 12px;font:inherit;font-size:14px;background:var(--surface);color:var(--text)}.mt{display:grid;grid-template-columns:repeat(4,1fr);gap:4px}.mt i{height:6px;border-radius:3px;background:#e6e6e2;transition:background .2s}.st{margin:6px 0;font-size:12.5px;font-weight:600}.ck{list-style:none;display:grid;gap:3px;font-size:12px;color:var(--muted)}.ck li::before{content:"\25CB ";}.ck li.ok{color:#1f7a45}.ck li.ok::before{content:"\2713 ";}.out{font-size:11.5px;color:var(--muted);margin:6px 0 0}.mini{height:30px;padding:0 14px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font-size:12px;font-weight:600;cursor:pointer}.mini:disabled{opacity:.4;cursor:default}@media (prefers-reduced-motion:reduce){.mt i{transition:none}}
@media (prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}}
</style></head>
<body><div class="stage">
<div class="bx"><label class="fl" for="pw">Password</label><div class="inp"><input id="pw" type="password" autocomplete="off" spellcheck="false" aria-describedby="hint"><button type="button" class="mini" id="sh" aria-pressed="false">Show</button></div><div class="mt" aria-hidden="true"><i></i><i></i><i></i><i></i></div><p class="st" id="st" role="status">Start typing.</p><ul class="ck" id="ck"></ul><p class="out" id="hint">This demo checks nothing on a server and stores nothing.</p></div>
</div>
<script>
const pw=document.getElementById('pw'),sh=document.getElementById('sh'),segs=[...document.querySelectorAll('.mt i')],st=document.getElementById('st'),ck=document.getElementById('ck');const COMMON=['password','123456','12345678','qwerty','letmein','111111','iloveyou','admin','welcome','abc123','password1','123456789'];const COL=['#d92d20','#e8832d','#d6b300','#1f9d55'],TX=['Very weak','Weak','Fair','Strong'];
function score(v){if(!v)return -1;if(COMMON.includes(v.toLowerCase()))return 0;let s=0;const L=v.length;if(L>=8)s++;if(L>=12)s++;if(L>=16)s++;const cls=[/[a-z]/,/[A-Z]/,/\d/,/[^A-Za-z0-9]/].filter(r=>r.test(v)).length;if(cls>=3&&L>=10)s++;if(/^(.)\1+$/.test(v)||/^(0123|1234|abcd|qwer)/i.test(v))s=Math.min(s,1);if(L<8)s=Math.min(s,1);return Math.max(0,Math.min(3,s-(L<8?0:0)-(s>3?1:0)));}
function up(){const v=pw.value,s=score(v);segs.forEach((e,i)=>e.style.background=s>=0&&i<=s?COL[s]:'#e6e6e2');
st.textContent=s<0?'Start typing.':TX[s]+(s===0&&COMMON.includes(v.toLowerCase())?' \u2013 this is a very common password.':s<3?' \u2013 add another word or a few more characters.':' \u2013 a long password is hard to guess.');
const R=[['At least 12 characters',v.length>=12],['Not a very common password',v&&!COMMON.includes(v.toLowerCase())],['Mixes words, numbers or symbols',/[a-z]/i.test(v)&&(/\d/.test(v)||/[^A-Za-z0-9]/.test(v)||/\s|-/.test(v))]];ck.innerHTML=R.map(r=>'<li class="'+(r[1]?'ok':'')+'">'+r[0]+'</li>').join('');}
pw.addEventListener('input',up);sh.addEventListener('click',()=>{const on=pw.type==='password';pw.type=on?'text':'password';sh.textContent=on?'Hide':'Show';sh.setAttribute('aria-pressed',String(on));});up();
</script>
</body></html>