Skip to content

Password Input with Strength Meter

Bootstrap 6 password field with show/hide toggle, the Strength meter, a live requirement checklist, confirm match, Caps Lock hint and a password generator.

Also known as: password strength meter, password show hide toggle, password requirements checklist, password generator input, confirm password field

Password Input with Strength Meter live demo

Open in new tab

Bootstrap 6 code (HTML, CSS, JS)

A password creation card for sign-up, reset and account settings pages. It is built around the new Bootstrap 6 Strength component. The field has a show/hide toggle, a four-segment strength meter with a text label and a live checklist of requirements. A confirm field checks that both passwords match, a Caps Lock hint appears while typing, and a button suggests a strong random password.

How it works

The root .pwm-root has a decorative .pwm-art panel with an inline SVG shield and the .pwm-form. The password sits in an .input-group with a .pwm-toggle button. Below it, .pwm-meter holds the Bootstrap .strength element with four .strength-segment children and a .strength-text label.

script.js imports Strength and creates the meter with Strength.getOrCreateInstance(). It passes the password input, custom messages and a scorer function. scorePassword() gives up to 8 points for length (8, 12 and 16 characters), lower case, upper case, digits, one symbol and two symbols. Bootstrap's default thresholds turn the score into weak, fair, good or strong. Bootstrap then sets data-bs-strength on the meter and colors the active segments. The checklist uses the same RULES object, so the meter and the ticks always agree.

The toggle switches both fields between password and text and updates aria-pressed, aria-label and the eye icon. The confirm field gets .is-valid or .is-invalid. "Suggest a strong one" creates a 16-character password with crypto.getRandomValues(), fills both fields and reveals them. Submit only succeeds with a good or strong password that matches the confirm field.

Customization

  • --pwm-weak, --pwm-fair, --pwm-good and --pwm-strong on .pwm-root: change the segment and label colors. They feed Bootstrap's --bs-strength-*-color tokens on .pwm-strength.
  • --pwm-blue on .pwm-root: recolors the buttons and focus rings through the scoped --bs-primary-* tokens.
  • RULES and scorePassword() in script.js: change the checklist rules or the scoring. Keep the .pwm-rule items in sync.
  • messages in the Strength.getOrCreateInstance() call: set the text shown for each level.
  • generatePassword(length) in script.js: change the default length or the character sets.
  • Remove the value attribute from #pwm-password for an empty first state, and replace the success message with a fetch() call.

Use cases

  • Sign-up pages: a live strength meter and requirements checklist guide users to a strong password
  • Password reset screens: confirm field checks that both passwords match before submitting
  • Account settings: show and hide toggle lets users verify what they typed, with a Caps Lock hint
  • Security-focused apps: a suggest button fills both fields with a random 16-character password

Accessibility

The strength text is an aria-live region and is linked to the password field with aria-describedby, together with the checklist. Each rule includes hidden "(done)" or "(missing)" text, because the icon color alone does not carry meaning. The toggle is a real button with aria-pressed and aria-controls. Feedback, the Caps Lock badge and status messages are text, not only color. Copy and paste are never blocked.

Bootstrap 6 notes

The Strength meter (.strength, .strength-segment, .strength-text) is new in Bootstrap 6. Bootstrap 5 needed a custom progress bar for this. Input group buttons use btn-outline theme-secondary input-group-btn, and badges use badge badge-subtle theme-warning. Built on Bootstrap 6.0.0-alpha.1, so APIs may still change. Icons come from Bootstrap Icons.

Password Input with Strength Meter at a glance

Framework
Bootstrap 6
Code
HTML, CSS, JavaScript
JavaScript
Vanilla JavaScript, no jQuery
Dependencies
Bootstrap 6, Bootstrap Icons
Layout
Responsive, works on mobile
Category
Inputs
License
Free for personal and commercial use

Questions about this template

Can I use the Password Input with Strength Meter code for free?

Yes. You can copy or download the code and use it in personal and commercial projects, including client work. No sign-up is needed. Reselling it as part of a component library or template collection is not allowed; see the license.

How do I add it to my website?

Load Bootstrap 6 and Bootstrap Icons from a CDN (the links are under Requirements). Paste the HTML where the component should appear, add the CSS to your stylesheet and load the JavaScript before the closing </body> tag. Download HTML gives you a complete page with everything already linked.

Does it need jQuery or a JavaScript framework?

No. The script is plain vanilla JavaScript, so it works without jQuery, React or Vue. You can still use the markup inside those frameworks.

Does it work on mobile?

Yes. The layout adapts to small screens. Use the Mobile and Tablet buttons above the live demo to check it at phone and tablet width.

Requirements

Add these to your page (already included in the download):

  • <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@6.0.0-alpha.1/dist/css/bootstrap.min.css">
  • <script type="module" src="https://cdn.jsdelivr.net/npm/bootstrap@6.0.0-alpha.1/dist/js/bootstrap.bundle.min.js"></script>
  • <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">

Built for Bootstrap 6.0.0-alpha.1. Bootstrap 6 ships as an ES module, so its script and this component's JavaScript load with type="module". Alpha releases can still change before the stable version.

Password Input with Strength Meter – Bootstrap 6 inputs component screenshot
Password Input with Strength Meter · Bootstrap 6 Inputs

More Inputs

Password Strength Meter – Bootstrap 5 inputs preview

Password Strength Meter

Bootstrap 5 password input with show/hide toggle, four-step strength meter, live requirements checklist and confirmation match check.

Inputs with Icons and Add-ons – Tailwind CSS inputs preview

Inputs with Icons and Add-ons

Tailwind CSS input group examples with leading icons, text prefixes and suffixes, a currency select, password toggle, clear button and helper text.

OTP Code Input – Bootstrap 6 inputs preview

OTP Code Input

Dark Bootstrap 6 OtpInput verification card with 6 digit slots, paste support, auto-advance, auto-verify on complete, error state and a resend countdown.

Input Groups with Icons and Buttons – Bootstrap 6 inputs preview

Input Groups with Icons and Buttons

Bootstrap 6 input group examples in a settings card: icon and text prefixes, suffixes, a currency menu, stepper, copy button and validated coupon field.

Floating Label Form Fields – Bootstrap 6 inputs preview

Floating Label Form Fields

Dark Bootstrap 6 project request form with floating label inputs, selects and a textarea, CSS-only validation, a character counter and simulated submit.

Tag Input with Removable Chips – Tailwind CSS inputs preview

Tag Input with Removable Chips

Tailwind CSS tag input that turns typed words into removable chips, with Enter and comma support, paste splitting, a tag limit and suggestions.