Skip to content

Login Modal

Bootstrap 5 login modal with social sign-in buttons, floating labels, a show/hide password toggle, client-side validation and a signed-in success view.

Also known as: sign in popup, login popup, login dialog, modal login form

Bootstrap 5 Modals Responsive #form #login #modal #sign-in #validation

Login Modal live demo

Open in new tab

Bootstrap 5 code (HTML, CSS, JS)

A Bootstrap 5 login modal with social sign-in buttons, floating-label email and password fields, a show/hide password toggle, client-side validation and a success view after signing in. It opens from a "Sign in" button in a small site header, the way most SaaS and content sites let visitors log in without leaving the page.

How it works

The root .lgm-root holds a demo header (.lgm-bar) with the .lgm-open trigger, a short hero and the .lgm-modal. The trigger uses Bootstrap's data-bs-toggle="modal" and data-bs-target="#lgm-modal", so the dialog opens, traps focus and closes with Escape through the Bootstrap bundle alone.

Inside .lgm-dialog there are two views. .lgm-view--form contains the logo, the .lgm-social buttons, an "or" .lgm-divider drawn with pseudo-elements, a hidden .lgm-error alert and the .lgm-form. The password field sits in .lgm-password with the absolutely positioned .lgm-reveal button, which switches the input between password and text and swaps the eye icon.

The script listens for shown.bs.modal to focus the email field and for submit on the form. Invalid forms get was-validated, aria-invalid on each field and focus on the first invalid one. A valid form shows a spinner and "Signing in…" in .lgm-submit, then hides the form view, shows .lgm-view--success with the email in .lgm-user, and changes .lgm-open__label to "My account". hide.bs.modal is cancelled while the request runs, and hidden.bs.modal resets everything for the next opening.

Customization

  • --lgm-accent, --lgm-accent-hover and --lgm-accent-rgb in .lgm-root: recolor the submit button, links, checkbox and focus rings.
  • --lgm-radius in .lgm-root: make the modal corners rounder or square.
  • --bs-modal-width in .lgm-modal: widen or narrow the dialog (default 27rem).
  • --lgm-page-bg in .lgm-root: change the background of the demo header and hero, or remove .lgm-bar and .lgm-hero and place the .lgm-open button in your own navbar.
  • minlength="8" on #lgm-password: change the password rule; also update the text of #lgm-password-error.
  • The window.setTimeout call in the submit handler of script.js: replace it with a fetch() POST to your login endpoint. On failure, put the server message in .lgm-error and remove its hidden attribute.
  • Delete the .lgm-social block and the .lgm-divider paragraph for an email-only login.

Use cases

  • SaaS sites: visitors sign in from a header button without leaving the page they are on
  • Content and membership sites: social sign-in buttons sit above floating-label email and password fields
  • Online stores: the header button changes to My account after a successful sign-in
  • Web apps: client-side validation and a show/hide password toggle reduce failed login attempts

Accessibility

The modal is labelled by #lgm-title. Every field has a real label, and the error messages are linked with aria-describedby. The reveal button has aria-controls, aria-pressed and a label that changes between "Show password" and "Hide password". While signing in the submit button uses aria-disabled instead of disabled, so keyboard focus is not lost; after success, focus moves to the success heading. The .lgm-error alert has role="alert". The check mark pop animation is turned off with prefers-reduced-motion: reduce.

Usage notes

Requires the Bootstrap 5 bundle and Bootstrap Icons. Client-side validation is only a convenience; always authenticate on the server and never log or store passwords in the browser.

Login Modal at a glance

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

Questions about this template

Can I use the Login Modal 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 5 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@5.3.3/dist/css/bootstrap.min.css">
  • <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/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">
Login Modal – free Bootstrap 5 modal template
Login Modal · free Bootstrap 5 modal template

More Modals

Multi-Step Wizard Dialog – free Bootstrap 6 modal template

Multi-Step Wizard Dialog

Bootstrap 6 Dialog wizard with three steps, a Stepper and progress bar, back/next buttons, per-step validation, Chips email invites and a review screen.

Image Lightbox Dialog – free Bootstrap 6 modal template

Image Lightbox Dialog

Dark Bootstrap 6 Dialog lightbox that opens gallery thumbnails large, with previous/next buttons, arrow-key and swipe navigation, captions and a photo counter.

Multi-Step Modal Dialog – free Tailwind CSS modal template

Multi-Step Modal Dialog

Tailwind CSS modal with a three-step wizard: template picker, validated details form and review, plus stepper, focus trap and Escape to close.

Product Quick View Modal with Photo – free Bootstrap 5 modal template

Product Quick View Modal with Photo

Bootstrap 5 product quick view modal with photo, rating, material and size options that update price and image, quantity stepper and add to cart.

Newsletter Popup Dialog – free Bootstrap 6 modal template

Newsletter Popup Dialog

Bootstrap 6 Dialog newsletter popup with a photo side, email signup with validation, a don't-show-again option, delayed auto-open and a confirmation state.

Fullscreen Dialog on Mobile – free Bootstrap 6 modal template

Fullscreen Dialog on Mobile

Dark Bootstrap 6 Dialog for notification settings that is centered on desktop, fullscreen on phones, with a scrollable body of switches and a sticky footer.