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 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.

Bootstrap Tables

We can create different types of responsive and awesome bootstrap table like: striped , border etc. Bootstrap Basic Table We can create a basic bootstrap table by using its class .table. It has...

3 minutes read.

Bootstrap Images

Bootstrap 4 Images Bootstrap provides several classes for images to make them responsive and also helps to give some style to the images. Image Shapes Rounded Corners Bootstrap 4 offers .rounded class that makes the corners...

5 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.

Difference between bootstrap.css and bootstrap-theme.css

The "bootstrap.css" uses to create a website with pre-existing designs and context. It uses basic Bootstrap classes like rows and columns with a CSS styling tool. The website is styled...

5 minutes read.

Bootstrap 4 Grid System

Bootstrap 4 Grid Systems Bootstrap offers a responsive and mobile-first grid system with the help of which we can divide the screen of the web browser into 12 horizontal parts. It has predefined classes...

4 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 Scrollspy

Bootstrap 4 Scrollspy Bootstrap 4 offers a scrollspy component that is used to make the website more attractive and eye-catching. Basically, the scrollspy is used on the single-page website. The scrollspy highlights the nav...

5 minutes read.

Bootstrap 4 Collapse

Bootstrap 4 Collapse Collapse is a bootstrap component that is similar to the dropdown button. Collapse is used to hide or show the content such as paragraphs, sentences, etc.  When we click on a...

4 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 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 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 Datepicker

What is a Bootstrap Datepicker? It is used to display a calendar with the date, month, and time from a dropdown menu. We will use an example to see how the date...

5 minutes read.

Bootstrap Typography

Bootstrap provides simple and easily customized typography for headings, body text, lists, and many more. Headline <h1> to <h6> By default, Bootstrap has HTML headings (<h1> to <h6>) that are given below: Example <h1>h1. Bootstrap heading</h1>   <h2>h2. Bootstrap heading</h2>   <h3>h3. Bootstrap heading</h3>   <h4>h4. Bootstrap heading</h4>   <h5>h5. Bootstrap heading</h5>   <h6>h6. Bootstrap heading</h6> Try Now ←...

1 minute read.

Bootstrap 4 Toast

Bootstrap 4 Toast Bootstrap 4 offers a Toast component, which is quite similar to the alert box and pushes notifications. The toast is visible on the screen for a few seconds when any...

5 minutes read.

Bootstrap 4 navbar

A navigation navbar or navbar uses in every website to make it more user-friendly. Navigating through the website is easier, and the user can instantly search for the topic of...

8 minutes read.

Bootstrap 4 Carousel

Bootstrap 4 Carousel Bootstrap 4 offers a carousel component, which is also known as a slider or slideshow. The carousel is used for the dynamic representation of content using images with...

7 minutes read.

Bootstrap Time Picker Example

What is a Bootstrap Time picker? It is used to display the time in hours, minutes and seconds from a dropdown menu. In this section, we will create an example to...

4 minutes read.

Bootstrap Glyphicons

Bootstrap Glyphicon is used to create different type of glyphicons It is used in the web project. It provides 260 Glyphicons from the Glyphivons Halflings set. There are various examples of...

1 minute 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.