Bootstrap Multiselect Dropdown

What is a multi-select Dropdown?

Multi-select dropdown lists are used when we want to select multiple options for a particular record. Usually, dropdown lists provide the feature of choosing just one value for a record. However, Bootstrap provides the functionality of creating multi-select dropdowns.

We can create custom categories of either dropdown or multi-select dropdown lists and define various items in each category.

How to make a Multiselect Dropdown?

First, include all the necessary CDNs in the <head> tag: The bootstrap CDN, the CSS CDN etc. The following CDNs that must be included are:

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.13.1/css/bootstrap-select.css" />
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.bundle.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.13.1/js/bootstrap-select.min.js"></script>

Now, include any Internal CSS you want to include in the <style> tag. For example,

<style>
.
.
.
</style>

Next, write the main code in the <body> tag, include the time picker component here,

<body>  
<div class ="container">  
    		<div class ="row"> 
 		.
		.
		</div>
	</div>
</body>

In the end, we can include the JavaScript required for the multiselect dropdown in the <script> tag as shown below,

 <script>
        $(function () {
    $('component').component();
});
</script>


Example 1:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Bootstrap Multiselect Dropdown</title>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.13.1/css/bootstrap-select.css" />
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.bundle.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.13.1/js/bootstrap-select.min.js"></script>
      <style>
        body {
   background-color: rgb(213, 213, 248);
    min-height: 100vh;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; color: rgb(6, 6, 73);
}


.bootstrap-select .bs-ok-default::after {
    width: 0.3em;
    height: 0.6em;
    border-width: 0 0.1em 0.1em 0;
    transform: rotate(45deg) translateY(0.5rem);
}
.btn.dropdown-toggle:focus {
    outline: none !important;
}
.btn-primary{
    margin: 0;
  position: absolute;
  top: 70%;
  left: 50%;
  -ms-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
}
    </style>
</head>
<body >
    <div class="container">
        <h2>Following is an example to demonstrate Multiselect Dropdown</h2><br>
            <p>Choose the following options to make a sandwhich.</p></br><br>
            
        <div class="row text-center">
            <div class="col-lg-6 mx-auto">
                <label class="mb-3 lead">Choose the bread from the list:</label>
                <!-- sauces -->
                <select multiple data-style="bg-white rounded-pill px-4 py-3 shadow-sm " class="selectpicker w-100">
                    <option>White Bread</option>
                    <option>Brown Bread</option>
                    <option>Multigrain Bread<option>
                    <option>Milk Bread</option>
                </select>
            </div>
            <div class="col-lg-6 mx-auto">
                <label class="mb-3 lead">Choose the vegetables from the list:</label>
                <!-- sauces -->
                <select multiple data-style="bg-white rounded-pill px-4 py-3 shadow-sm " class="selectpicker w-100">
                    <option>Cucumber</option>
                    <option>Tomato</option>
                    <option>Lettuce<option>
                    <option>Pickles</option>
                    <option>Onion</option>
                    <option>Cheese</option>
                </select>
            </div>
            <div class="col-lg-6 mx-auto">
                <label class="mb-3 lead">Choose the sauces from the list:</label>
                <!-- sauces -->
                <select multiple data-style="bg-white rounded-pill px-4 py-3 shadow-sm " class="selectpicker w-100">
                    <option>Mustard</option>
                    <option>Barbeque</option>
                    <option>Ranch<option>
                    <option>Chipotle Sauce</option>
                    <option>Ketchup</option>
                    <option>White Mayo</option>
                </select>
            </div>
        </div>
        <button type="button" class="btn btn-primary">Make the sandwhich</button>
    </div>
    <script>
        $(function () {
    $('.selectpicker').selectpicker();
});
    </script>
</body>
</html>

Output:

Initially, the screen looks like this,

Bootstrap Multiselect Dropdown

Example 2:

<!DOCTYPE html>
<html>
<head>
        <link rel="stylesheet" href="https://netdna.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
        <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/bbbootstrap/libraries@main/choices.min.css">
        <script src="https://cdn.jsdelivr.net/gh/bbbootstrap/libraries@main/choices.min.js"></script>
<style>
body {
    
    margin-top: 100px;
    background-color: rgb(19, 19, 5);
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    color: #514B64;
    min-height: 100vh;
}
.content{
    align-items: center;
    align-content: center;
}
.para{
    color: white;
    align-items: center;
    align-content: center;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-size: larger;
}
</style>
</head>
<body>
<div class="container">
<div class="row">
    <p class="para">Following is an example to demonstrate the multiselect dropdown using Bootstrap.</p></br>
    <div class="col-md-12 content"> 
        <select id="multipleselect" placeholder="Hello! You can choose upto 5 colors of your choice." multiple>
            <option value="Red">Red</option>
            <option value="Yellow">Yellow</option>
            <option value="Green">Green</option>
            <option value="Purple">Purple</option>
            <option value="Orange">Orange</option>
            <option value="Mauve">Mauve</option>
            <option value="Black">Black</option>
            <option value="White">White</option>
            <option value="Cyan">Cyan</option>
            <option value="Pink">Pink</option>
            <option value="Gray">Gray</option>
        </select> </div>
</div>
</div>
<script>
$(document).ready(function(){
var multipleSelectButton = new Choices('#multipleselect', {
removeItemButton: true,
maxItemCount:5,
});
});
</script>
</body>
</html>

Output:

Initially, the screen looks like this,

Bootstrap Multiselect Dropdown

We can now use the dropdown to select at max five options,

Bootstrap Multiselect Dropdown

Related Topics

Bootstrap Protocol (BOOTP)

In the following article, we will learn about the Bootstrap Protocol and how it maintains contracts among linked devices on webwork. What is Bootstrap Protocol? The Bootstrap Protocol is a webwork contract...

3 minutes read.

Text Shadows in CSS

Text shadows are created with the text-shadow CSS property. It takes a list of shadows separated by commas to be applied to the text and any of its styles. Each...

5 minutes read.

Bootstrap Pager

← Prev Next → ...

1 minute read.

Bootstrap Grid System Example

Bootstrap Grid System Example Stacked to horizontal – In stacked to the horizontal grid system, the grid columns are stacked on top of each other on extra small devices and becomes...

7 minutes read.

Bootstrap 4 Spinners

Bootstrap 4 offers spinner is a loading indicator that is used to display the loading state of any component or web page. The spinner is also known as a loader...

7 minutes read.

Bootstrap Validation Example

Validation We can provide valuable and actionable feedback to the users through an HTML form validation. It happens via custom styles or behaviors of default browsers and JavaScript. How does validation work...

4 minutes read.

Bootstrap 4 Popover

Bootstrap 4 Popover Popover A popover is similar to the tooltip. The only difference between tooltip and Popover is that in the tooltip, the popup box appears when you move the cursor...

6 minutes read.

Environment Setup

How to use Bootstrap? We can use bootstrap in our project either by downloading or by providing link of the library files. 1) Download Bootstrap files To download files, visit official site of bootstrap www.getbootstrap.com/download/ and...

1 minute read.

Bootstrap 4 Progress Bar

Bootstrap Progress Bar Bootstrap 4 offers progress bars that are used to represent the progress of tasks such as downloading a file, software installation, etc. on the computer. It represents the percentage of the...

9 minutes read.

Bootstrap 4 Tutorial

What is Bootstrap? Bootstrap is a CSS (Cascading Style Sheets) framework, which is used to develop a responsive website. It is an open-source and mobile-first front-end framework. It has design templates that are based...

4 minutes read.

Bootstrap 4 List Groups

Bootstrap 4 List Groups Bootstrap 4 offers List Group component, which is used to display a series of content in an organized way. The most common list group is an unordered...

13 minutes read.

Bootstrap Toast Example

What are toasts? Toasts are similar to notifications, and they are lightweight and act as push notifications from mobile and desktop operating systems. They’re built using flexbox in Bootstrap. They can...

4 minutes read.

Bootstrap Wells

In Bootstrap, well are used to add a rounded border around an element. It is default some padding and gray background color. It is like a container that displays the content....

1 minute read.

Difference between Bootstrap and WordPress

What is WordPress? WordPress is a free open-source CMS (Content Management System) that is written using Hypertext Pre-processor (PHP) and is paired with MySQL and is supported with HTTPS (Hypertext Transfer...

3 minutes read.

Bootstrap 4 Icons

Bootstrap 4 Icons Bootstrap 3 contains the default icon library. But in bootstrap 4, you have to include the external icon library by yourself. Many free icon libraries are available such...

2 minutes read.

Bootstrap 4 Modal

Bootstrap 4 Modal The Modal is a component of Bootstrap 4, which is a dialog box or pop-up window. The modals are used to provide information or warning to the user, such as...

18 minutes read.

Bootstrap First Example

1) Add HTML5 doctype Before starting the example of Bootstrap, we should know about the some basic rules of Bootstrap. We have to add HTML5 doctype with lang element and CSS properties. <!DOCTYPE html>   <html lang="en">     <head>       <meta charset="utf-8">      </head>   </html> 2) Bootstrap...

2 minutes read.

Bootstrap Input groups

Bootstrap 4 Input groups The input group is a component of Bootstrap 4, which is used to create interactive and stylish form controls. With the help of input groups, you can easily customize the input...

8 minutes read.

Bootstrap 4 Margin classes

Bootstrap 4 contains a variety of brief, responsive margin and padding utility classes to change the appearance of an element. The Bootstrap 4 margin classes use for the outer spacing of...

8 minutes read.

Bootstrap 4 Tooltip

Bootstrap 4 Tooltip Tooltip Bootstrap 4 offers a tooltip component, a small popup box that appears when you move the cursor over an element such as buttons or any highlighted element. It...

3 minutes read.