Bootstrap 5 Search Form Tutorial: Step-by-Step Example

Ruth Jul 09, 2026

Bootstrap 5, the latest iteration of the popular front-end framework, offers a robust set of tools for creating responsive and mobile-first websites. One of the most essential elements of any website is the search form, and Bootstrap 5 provides an easy-to-implement solution for this. Let's delve into an example of creating a search form using Bootstrap 5.

34 Best Bootstrap Search Box Examples 2026 - uiCookies
34 Best Bootstrap Search Box Examples 2026 - uiCookies

Before we dive into the code, it's important to note that Bootstrap 5 uses a different approach to forms compared to its predecessors. It now uses a more semantic and accessible approach, which means we'll be using the new <form> and <input> elements instead of the old <div> and <span> based structure.

the homepage for an employee portal with a rocket ship in the background and text that reads, apply as a employee
the homepage for an employee portal with a rocket ship in the background and text that reads, apply as a employee

Setting Up the Bootstrap 5 Environment

Before we start creating our search form, we need to set up our Bootstrap 5 environment. This involves including the Bootstrap CSS and JavaScript files in our HTML document. You can either download these files or use a CDN (Content Delivery Network) to include them.

Free 22+ HTML5 Signup & Registration Forms - HTML, CSS
Free 22+ HTML5 Signup & Registration Forms - HTML, CSS

Here's how you can include Bootstrap 5 using a CDN:

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

Creating the Basic Search Form Structure

37 Free Bootstrap Form Templates You Can Try Right Now
37 Free Bootstrap Form Templates You Can Try Right Now

Now that we have our Bootstrap 5 environment set up, let's create the basic structure of our search form. We'll use the new <form> element and place it inside a Bootstrap 5 container for responsiveness.

Here's the basic structure of our search form:

<div class="container my-5">
  <form>
    <-- Search form input and button will go here -->
  </form>
</div>

Adding the Search Input and Button

Bootstrap Forms
Bootstrap Forms

Next, we'll add the search input field and button to our form. Bootstrap 5 uses the form-control class for input fields and the btn class for buttons. We'll also use the w-100 class to make the input field full-width.

Here's how we can add the search input and button to our form:

<div class="container my-5">
  <form>
    <div class="input-group mb-3">
      <input type="text" class="form-control w-100" placeholder="Search...">
      <button class="btn btn-outline-secondary" type="button" id="button-addon2">Search</button>
    </div>
  </form>
</div>

Styling the Search Form

📝 Create Forms in HTML
📝 Create Forms in HTML

Bootstrap 5 provides several utility classes that we can use to style our search form. Let's add some basic styling to make our search form stand out.

Here's how we can style our search form using Bootstrap 5 utility classes:

Bootstrap 5 popup form
Bootstrap 5 popup form
the bootstap login and register forms page
the bootstap login and register forms page
BOOTSTRAP INPUT FORM (2020) | HOW TO MAKE FORM IN BOOTSTRAP
BOOTSTRAP INPUT FORM (2020) | HOW TO MAKE FORM IN BOOTSTRAP
Wizard
Wizard
Form
Form
the login screen for an email address
the login screen for an email address
30 Best Free Bootstrap Wizards & Forms 2026 - Colorlib
30 Best Free Bootstrap Wizards & Forms 2026 - Colorlib
55 Best Free Bootstrap Registration Form Designs 2026 - Colorlib
55 Best Free Bootstrap Registration Form Designs 2026 - Colorlib
Bootstrap Navbar Guide and Free Navigation Examples
Bootstrap Navbar Guide and Free Navigation Examples
📝 Create Text Input Forms and Submit Button in HTML
📝 Create Text Input Forms and Submit Button in HTML
the login screen for google forms, which is open to allow users to sign in and
the login screen for google forms, which is open to allow users to sign in and
the login form is displayed on a purple and blue background
the login form is displayed on a purple and blue background
the different dropdowns page in wordpress
the different dropdowns page in wordpress
the login page for wordpress with an arrow pointing up to the account information section
the login page for wordpress with an arrow pointing up to the account information section
20 Beautiful CSS Contact Forms Code Examples - OnAirCode
20 Beautiful CSS Contact Forms Code Examples - OnAirCode
Build a Survey Form using HTML and CSS - GeeksforGeeks
Build a Survey Form using HTML and CSS - GeeksforGeeks
Bootstrap Registration Forms: 3 Free Responsive Templates | AZMIND
Bootstrap Registration Forms: 3 Free Responsive Templates | AZMIND
Bootstrap 4 Cheat Sheet - The ultimate list of Bootstrap classes
Bootstrap 4 Cheat Sheet - The ultimate list of Bootstrap classes
Create Html Forms Using Lists and Css/Html
Create Html Forms Using Lists and Css/Html
9
9

<div class="container my-5">
  <form class="p-3 bg-light rounded shadow">
    <div class="input-group mb-3">
      <input type="text" class="form-control w-100" placeholder="Search...">
      <button class="btn btn-primary" type="button" id="button-addon2">Search</button>
    </div>
  </form>
</div>

Adding Form Validation

Bootstrap 5 also provides built-in form validation features. Let's add some basic validation to our search form to ensure that the user has entered something before they can submit the form.

Here's how we can add form validation to our search form:

<div class="container my-5">
  <form class="p-3 bg-light rounded shadow">
    <div class="input-group mb-3">
      <input type="text" class="form-control w-100" placeholder="Search..." required>
      <button class="btn btn-primary" type="submit" id="button-addon2">Search</button>
    </div>
    <div class="invalid-feedback">Please enter a search term.</div>
  </form>
</div>

Adding JavaScript for Form Submission

Finally, let's add some JavaScript to handle the form submission. We'll use the addEventListener method to listen for the form's submit event, and then we can perform some action with the user's search term.

Here's an example of how we can handle the form submission using JavaScript:

<script>
  document.querySelector('form').addEventListener('submit', function(event) {
    event.preventDefault();
    var searchTerm = event.target.elements[0].value;
    console.log('Searching for:', searchTerm);
  });
</script>

And that's it! We've created a responsive and stylish search form using Bootstrap 5. This form includes basic styling, form validation, and JavaScript handling for form submission. You can further customize this form to fit the specific needs of your website.