Bootstrap, the popular open-source CSS framework, has just released its fifth iteration, Bootstrap 5. With it comes a host of new features and improvements, including a revamped forms system. In this tutorial, we'll guide you through the process of creating responsive and stylish forms using Bootstrap 5.

Before we dive in, ensure you have the latest version of Bootstrap 5 installed. You can include it via a CDN in your HTML file or download and host the files locally. For this tutorial, we'll use the CDN method. Add the following lines in the
section of your HTML file:
Setting Up Bootstrap 5 Forms
Once Bootstrap 5 is set up, you're ready to start building forms. Bootstrap 5 uses a mobile-first approach, meaning your forms will be responsive and optimized for smaller screens by default.

To create a basic form, wrap your form elements within the <form> tag and add the class="needs-validation" attribute. This will enable Bootstrap's validation styles and JavaScript functionality.
Basic Form Structure

Here's a basic example of a form structure in Bootstrap 5:
<form class="needs-validation" novalidate>
<div class="mb-3">
<label for="exampleInputEmail1" class="form-label">Email address</label>
<input type="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp">
<div id="emailHelp" class="form-text">We'll never share your email with anyone else.</div>
</div>
<div class="mb-3">
<label for="exampleInputPassword1" class="form-label">Password</label>
<input type="password" class="form-control" id="exampleInputPassword1">
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
In this example, we have two input fields for email and password, along with a submit button. The mb-3 class adds margin-bottom to create space between form elements.
Form Validation

Bootstrap 5 includes built-in form validation. To use it, add the required attribute to your input fields. For more complex validation, you can use JavaScript or a library like jQuery.
Here's an updated example with validation:
<form class="needs-validation" novalidate>
<div class="mb-3">
<label for="exampleInputEmail1" class="form-label">Email address</label>
<input type="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" required>
<div id="emailHelp" class="form-text">We'll never share your email with anyone else.</div>
</div>
<div class="mb-3">
<label for="exampleInputPassword1" class="form-label">Password</label>
<input type="password" class="form-control" id="exampleInputPassword1" required>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
Now, when a user tries to submit the form without filling out the required fields, they'll see validation messages and the form won't submit.

Advanced Form Elements
Bootstrap 5 offers a variety of advanced form elements to enhance user experience. Let's explore some of them.




















Form Select
The <select> element in Bootstrap 5 is customizable with the form-select class. Here's an example:
<select class="form-select" aria-label="default select example">
<option selected>Open this select menu</option>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>
You can also add size="n" attribute to create a multi-select dropdown with n options visible at once.
Form Check and Radio Buttons
Bootstrap 5 introduces a new <form> element called <form-check> for checkboxes and radio buttons. Here's an example:
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="flexCheckDefault">
<label class="form-check-label" for="flexCheckDefault">Default checkbox</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="flexRadioDefault" id="flexRadioDefault1">
<label class="form-check-label" for="flexRadioDefault1">Default radio</label>
</div>
These new elements provide better accessibility and customization options.
That's it! You now know how to create responsive and stylish forms using Bootstrap 5. Happy coding, and don't forget to explore the official Bootstrap 5 documentation for more features and examples.