Signup/Sign In

How to create Bootstrap Multiselect dropdown?

The Bootstrap Multiselect allows the user to select more than one option at a time, unlike normal Select where you can choose only one option. In this tutorial, we will learn to create multiselect with Bootstrap 5.

Creating a Multiselect

To create a multiselect use <select> tag with .form-select class. Add items within <option> tag. For multi-select of the items use multiple attribute within <select>. We can also use size attributes to define the number of select items in the list.

Example: Creating multiselect dropdown with multiple attribute

In this example, we have used multiple attribute to select multiple items in the dropdown.

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap </title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css" rel="stylesheet"> 
  <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.2/dist/umd/popper.min.js" integrity="sha384-IQsoLXl5PILFhosVNubq5LC7Qb9DXgDA9i+tQ8Zj3iwWAwPtgFTxbJ8NT4GN1R8p" crossorigin="anonymous"></script>
  <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/js/bootstrap.min.js" integrity="sha384-Atwg2Pkwv9vp0ygtn1JAojH0nYbwNJLPhwyoVbhoPwBhjQPR5VtM2+xf0Uwh9KtT" crossorigin="anonymous"></script></head>

<body>
    <h2> Multiselect dropdown </h2>
	<select class="form-select" multiple aria-label="multiple 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>
</body>
</html>

Output

Here is the output of the above code.

multiselect dropdown

Example: Creating a multiselect dropdown using size attribute

In this example, we have used the size attribute to create a multiselect dropdown with bootstrap 5.

Conclusion

In this tutorial, we have learned to create multiselect dropdown with CSS. Here we have used <select> attribute t do so. Use either multiple of size attribute for multi-select.