Bootstrap 5 Login Example

Ruth Jul 09, 2026

Bootstrap, the popular CSS framework, has evolved significantly with its fifth iteration, Bootstrap 5. One of the key components of any web application is user authentication, and Bootstrap 5 provides robust tools to create responsive and visually appealing login forms. Let's explore a comprehensive example of a Bootstrap 5 login form.

Best Free Bootstrap Login Forms » CSS Author
Best Free Bootstrap Login Forms » CSS Author

Before diving into the code, it's essential to understand that Bootstrap 5 uses a different approach to forms compared to its predecessors. It now relies on custom form validation and input groups, making the process more flexible and customizable.

Free Bootstrap 4 Login Form
Free Bootstrap 4 Login Form

Setting Up the Bootstrap 5 Environment

To get started with Bootstrap 5, you'll first need to include the necessary CSS and JavaScript files in your project. You can either download the files or use a CDN. For this example, we'll use the CDN version:

three screens showing the user's avatars for bootstrap 4, with mountains in the background
three screens showing the user's avatars for bootstrap 4, with mountains in the background

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"></script>

Creating the Basic Login Form Structure

Bootstrap 5 Login Form Template
Bootstrap 5 Login Form Template

Now that we have the Bootstrap environment set up, let's create the basic structure of our login form. We'll use Bootstrap's grid system and form controls to build a responsive layout:

<div class="container my-5"> <div class="row justify-content-center"> <div class="col-md-6"> <form> <h2 class="text-center mb-4">Login</h2> <div class="mb-3"> <label for="email" class="form-label">Email address</label> <input type="email" class="form-control" id="email" placeholder="name@example.com"> </div> <div class="mb-3"> <label for="password" class="form-label">Password</label> <input type="password" class="form-control" id="password"> </div> <button type="submit" class="btn btn-primary w-100">Login</button> </form> </div> </div> </div>

Adding Custom Form Validation

40 Best Free Bootstrap Login Form Templates 2026 - Colorlib
40 Best Free Bootstrap Login Form Templates 2026 - Colorlib

Bootstrap 5 introduces a new way of handling form validation using JavaScript. We'll use the `form-check` class to add validation to our form:

<script> (function () { 'use strict' // Fetch all the forms we want to apply custom Bootstrap validation styles to const forms = document.querySelectorAll('.needs-validation') // Loop over them and prevent submission Array.from(forms).forEach(function (form) { form.addEventListener('submit', function (event) { if (!form.checkValidity()) { event.preventDefault() event.stopPropagation() } form.classList.add('was-validated') }, false) }) })() </script>

Now, add the `needs-validation` class to our form and update the input fields with the appropriate validation attributes:

the gratify login screen is shown in this screenshote image, it appears to be dark blue
the gratify login screen is shown in this screenshote image, it appears to be dark blue

<form class="needs-validation" novalidate>
<input type="email" class="form-control" id="email" placeholder="name@example.com" required>
<input type="password" class="form-control" id="password" required>

Styling the Login Form

Sign in & Sign up in one page with Luxury Design
Sign in & Sign up in one page with Luxury Design
Login Form Template Bootstrap 5
Login Form Template Bootstrap 5
Login page through HTML and CSS
Login page through HTML and CSS
Welcome screen design
Welcome screen design
the login screen for an email address
the login screen for an email address
a login screen with mountains and trees in the background at night, under a full moon
a login screen with mountains and trees in the background at night, under a full moon
Login Page Bootstrap | Froala
Login Page Bootstrap | Froala
two people standing in front of a computer screen with the word login on it
two people standing in front of a computer screen with the word login on it
Bootstrap 5 popup form
Bootstrap 5 popup form
Login Form 11 by Colorlib - Free HTML Login Form 2026 - Colorlib
Login Form 11 by Colorlib - Free HTML Login Form 2026 - Colorlib
40 Best Free Bootstrap Login Form Templates 2026 - Colorlib
40 Best Free Bootstrap Login Form Templates 2026 - Colorlib
How To Make A Website With Login And Register | HTML CSS & Javascript
How To Make A Website With Login And Register | HTML CSS & Javascript
the bootstap login and register forms page
the bootstap login and register forms page
Login page UI Design
Login page UI Design
the sign in page for a website
the sign in page for a website
a group of people walking down a hallway with backpacks on their back and the words welcome
a group of people walking down a hallway with backpacks on their back and the words welcome
FORM connect bootstrap
FORM connect bootstrap
the login page for an app with blue and white shapes
the login page for an app with blue and white shapes
a green login form on a computer screen
a green login form on a computer screen
the login screen is displayed in front of a purple background with abstract shapes and lines
the login screen is displayed in front of a purple background with abstract shapes and lines

To make our login form more visually appealing, we can add some custom styles and use Bootstrap's utility classes:

.container { max-width: 720px; }
.form-label { font-weight: 500; }
.btn-primary { font-size: 1rem; }
.was-validated .form-control:invalid { border-color: #dc3545; }
.was-validated .form-control:valid { border-color: #198754; }

Adding a Forgot Password Link

Let's add a forgotten password link to our form using Bootstrap's inline text elements:

<div class="d-flex justify-content-between align-items-center mb-3"> <a href="#" class="text-decoration-none text-muted">Forgot password?</a> <a href="#" class="text-decoration-none text-muted">Create account</a> </div>

With these steps, you now have a fully functional and visually appealing login form using Bootstrap 5. You can further customize the form by adding more input fields, using different form controls, or incorporating custom JavaScript functionality.

As the web development landscape continues to evolve, so does Bootstrap. By keeping up with the latest updates and best practices, you can ensure that your login forms remain responsive, accessible, and visually appealing across various devices and platforms.