Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Bootstrap5 Dropdowns

Bootstrap5 Dropdowns

A dropdown is toggleable, a contextual menu that displays links in a list format.

Example

<div class="dropdown">
<button type="button" class=">

btn btn-primary dropdown-toggle

"

data-bs-toggle

=

"

dropdown

"

Dropdown menu buttons

button

<div class="dropdown-menu">
<a class="dropdown-item" href="">

Link 1

a

<a class="dropdown-item" href="">

Link 2

a

<a class="dropdown-item" href="">

Link 3

a

div

div

Try it »

Example Parsing

The .dropdown class is used to specify a dropdown.

We can use a button or link to open the dropdown; the button or link needs the .dropdown-toggle class and the data-toggle="dropdown" attribute.

Add the .dropdown-menu class on the element to set the actual dropdown menu, then add the .dropdown-item class to the options in the dropdown menu.

Dividers in a Dropdown

The .dropdown-divider class is used to create a horizontal divider in the dropdown:

Example

<li>
<hr class="dropdown-divider" hr li>

Try it »


Headers in Dropdowns

The .dropdown-header class is used to add a header in the dropdown:

Example

<li>
<h5 class="dropdown-header">

Heading 1

h5

li

Try it »


Enabled and Disabled Items in Dropdowns

The .active class highlights a dropdown option (adds a blue background).

To disable a dropdown option, you can use the .disabled class.

Example

<a class="dropdown-item" href="">

Regular Item

a

<a class=">

dropdown-item active

"

href

=

"

"

Active Item

a

<a class=">

dropdown-item disabled

"

href

=

"

"

Disabled Item

a

Try it »


Dropdown Alignment

If we want to right-align the dropdown menu, we can add the .dropend or .dropstart class after the .dropdown class on the element.

.dropend is right-aligned, .dropstart is left-aligned.

Example

<div class=">

dropdown dropend

"

...

div

<div class=">

dropdown dropstart

"

...

div

Try it »


Setting the Dropdown Direction

The dropdown direction defaults to downward, but of course we can set a different direction.

Specifying a Right-aligned Dropdown

If you want the dropdown menu to pop out to the lower right, you can add the .dropdown-menu-end class on the div element:

Example

<div class=">

dropdown dropdown-menu-end

"

<button type="button" class=">

btn btn-primary dropdown-toggle

"

data-bs-toggle

=

"

dropdown

"

Dropdown Menu Pops Out to Lower Right

button

<ul class="dropdown-menu">
<li>
<a class="dropdown-item" href="">

Link 1

a

li

<li>
<a class="dropdown-item" href="">

Link 2

a

li

<li>
<a class="dropdown-item" href="">

Link 3

a

li

ul

div

Try it »

Specifying an Upward Dropup

If you want the dropup to pop up, you can add the "dropup" class to the div element:

Example

<div class="dropup">
<button type="button" class=">

btn btn-primary dropdown-toggle

"

data-bs-toggle

=

"

dropdown

"

Dropdown menu

button

<ul class="dropdown-menu">
<li>
<a class="dropdown-item" href="">

Link 1

a

li

<li>
<a class="dropdown-item" href="">

Link 2

a

li

<li>
<a class="dropdown-item" href="">

Link 3

a

li

ul

div

Try it »

Specifying a Left-aligned Dropdown

If you want the dropdown menu to pop up, you can add the dropstart class on the div element:

Example

<div class="dropstart">

Add some content to test the left pop-out effect.

<button type="button" class=">

btn btn-primary dropdown-toggle

"

data-bs-toggle

=

"

dropdown

"

Dropdown menu

button

<ul class="dropdown-menu">
<li>
<a class="dropdown-item" href="">

Link 1

a

li

<li>
<a class="dropdown-item" href="">

Link 2

a

li

<li>
<a class="dropdown-item" href="">

Link 3

a

li

ul

div

Try it »


Dropdown Text

The .dropdown-item-text class can set text items in the dropdown:

Example

<ul class="dropdown-menu">
<li>
<a class="dropdown-item" href="">

Link 1

a

li

<li>
<a class="dropdown-item" href="">

Link 2

a

li

<li>
<a class="dropdown-item" href="">

Link 3

a

li

<li>
<a class="dropdown-item-text" href="">

Text Link

a

li

<li>
<span class="dropdown-item-text">

Just text

span

li

ul

Try it »


Setting a Dropdown in a Button Group

We can add a dropdown inside a button:

Example

<div class="btn-group">
<button type="button" class=">

btn btn-primary

"

Apple

button

<button type="button" class=">

btn btn-primary

"

Samsung

button

<div class="btn-group">
<button type="button" class=">

btn btn-primary dropdown-toggle

"

data-bs-toggle

=

"

dropdown

"

Sony

button

<ul class="dropdown-menu">
<li>
<a class="dropdown-item" href="" Tablet a li>
<li>
<a class="dropdown-item" href="" Smartphone a li ul div div>

Try it »

Vertical Button Group with Dropdown:

Example

<div class="btn-group-vertical">
<button type="button" class=">

btn btn-primary

"

Apple

button

<button type="button" class=">

btn btn-primary

"

Samsung

button

<div class="btn-group">
<button type="button" class=">

btn btn-primary dropdown-toggle

"

data-bs-toggle

=

"

dropdown

"

Sony

button

<ul class="dropdown-menu">
<li>
<a class="dropdown-item" href="" Tablet a li>
<li>
<a class="dropdown-item" href="" Smartphone a li ul div div>

Try it »


Navbar Example

Example

Try it »