Bootstrap, the popular CSS framework, has evolved significantly over the years, and with the release of Bootstrap 5, it has introduced several new features and improvements. One of the notable changes is the revamped search functionality, which now uses Bootstrap's new input group feature. Let's dive into an example of how to create search results using Bootstrap 5.

Before we start, ensure you have included the Bootstrap 5 CDN in your project's HTML file. If you haven't, add the following line within the
section:
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet">
Now, let's create a simple search form and display the results using Bootstrap 5.
Creating the Search Form

The first step is to create a basic search form using Bootstrap's input group feature. This allows us to combine form inputs and add-ons like buttons and icons in a single, flexible container.
Here's a simple example of a search form:

<div class="input-group mb-3"> <input type="text" class="form-control" placeholder="Search..."> <button class="btn btn-outline-secondary" type="button" id="search-btn">Search</button> </div>
Styling the Search Form
By default, the search form will have some basic styling. However, you can customize it further to match your website's design. For instance, you can change the button's color or add some padding to the input field:
<style>
.input-group .form-control {
padding: 1.5rem;
}
#search-btn {
background-color: #007bff;
color: white;
}
</style>
Displaying Search Results

Once the user submits the search query, we need to display the results. For this example, let's assume we have an array of items to search through. We'll use jQuery to handle the search functionality and display the results in a list.
First, include the jQuery library in your project's HTML file:
<script src="https://code.jquery.com/jquery-3.6.1.min.js"></script>
Implementing the Search Functionality

Now, let's add the jQuery script to handle the search functionality. In this example, we'll use a simple array of items and filter them based on the user's input:
<script>
$(document).ready(function () {
const items = [
'Item 1',
'Item 2',
'Item 3',
'Item 4',
'Item 5',
// Add more items as needed
];
$('#search-btn').click(function () {
const query = $('#search-input').val().toLowerCase();
const filteredItems = items.filter(item => item.toLowerCase().includes(query));
// Display the results
$('#search-results').empty();
filteredItems.forEach(item => {
$('#search-results').append(`<li>${item}</li>`);
});
});
});
</script>
Displaying the Search Results




















Finally, add a list element to display the search results:
<ul id="search-results" class="list-group"></ul>
With this setup, when the user clicks the search button, the script will filter the items based on the input and display the results in the list.
In conclusion, creating search results with Bootstrap 5 is a breeze, thanks to its new input group feature and the flexibility of jQuery. This example demonstrates a simple search form and results display, but you can further customize and expand this functionality to suit your project's needs. Happy coding!