Skip to docs navigation

Dropdowns

Overview

Note: Be sure to include popper.min.js before Bootstrap’s JavaScript or use the Bootstrap bundle.

Accessibility

Note: Since dropdowns have many uses, Bootstrap does not expect (nor automatically add) any of the role and aria- attributes required for true ARIA menus. Authors will have to include these more specific attributes themselves.

Examples

Single button

Any single .btn can be turned into a dropdown toggle with some markup changes. Here’s how you can put them to work with either <button> elements:

And with <a> elements:

The best part is you can do this with any button variant, too:

Split button

Add .dropdown-toggle-split for proper spacing around the dropdown caret.

Sizing

Dark dropdowns

Add .dropdown-menu-dark

And putting it to use in a navbar:

Directions

RTL

Directions are mirrored when using Bootstrap in RTL, meaning .dropstart will appear on the right side.

Dropup

Dropright

Dropleft

You can optionally use <button> elements in your dropdowns instead of just <a>s.

You can also create non-interactive dropdown items with .dropdown-item-text.

Active

Disabled

Heads up! Dropdowns are positioned thanks to Popper (except when they are contained in a navbar).

Responsive alignment

If you want to use responsive alignment, disable dynamic positioning by adding the data-bs-display="static" attribute and use the responsive variation classes.

To align right the dropdown menu with the given breakpoint or larger, add .dropdown-menu{-sm|-md|-lg|-xl|-xxl}-end.

To align left the dropdown menu with the given breakpoint or larger, add .dropdown-menu-end and .dropdown-menu{-sm|-md|-lg|-xl|-xxl}-start.

Note that you don’t need to add a data-bs-display="static" attribute to dropdown buttons in navbars, since Popper isn’t used in navbars.

Headers

Dividers

Text

Forms

Use data-bs-offset or data-bs-reference to change the location of the dropdown.

Usage

Via data attributes or JavaScript, the dropdown plugin toggles hidden content (dropdown menus) by toggling the .show class on the parent .dropdown-menu. The data-bs-toggle="dropdown" attribute is relied on for closing dropdown menus at an application level, so it’s a good idea to always use it.

On touch-enabled devices, opening a dropdown adds empty `mouseover` handlers to the immediate children of the `` element. This admittedly ugly hack is necessary to work around a [quirk in iOS' event delegation](https://www.quirksmode.org/blog/archives/2014/02/mouse_event_bub.html), which would otherwise prevent a tap anywhere outside of the dropdown from triggering the code that closes the dropdown. Once the dropdown is closed, these additional empty `mouseover` handlers are removed.

Via data attributes

Add data-bs-toggle="dropdown" to a link or button to toggle a dropdown.

Via JavaScript

Call the dropdowns via JavaScript:

data-bs-toggle="dropdown" still required

Regardless of whether you call your dropdown via JavaScript or instead use the data-api, data-bs-toggle="dropdown" is always required to be present on the dropdown’s trigger element.

Options

Options can be passed via data attributes or JavaScript. For data attributes, append the option name to data-bs-, as in data-bs-offset="".

Name Type Default Description
flip boolean true Allow Dropdown to flip in case of an overlapping on the reference element. For more information refer to Popper's flip docs.
boundary string | element 'scrollParent' Overflow constraint boundary of the dropdown menu. By default it's 'clippingParents' and can accept an HTMLElement reference (JavaScript only). For more information refer to Popper's preventOverflow docs.
reference string | element 'toggle' Reference element of the dropdown menu. Accepts the values of 'toggle', 'parent', or an HTMLElement reference. For more information refer to Popper's constructor docs.
display string 'dynamic' By default, we use Popper for dynamic positioning. Disable this with static.
popperConfig null | object null To change Bootstrap's default Popper config, see Popper's configuration

Note when boundary is set to any value other than 'scrollParent', the style position: static is applied to the .dropdown container.

Methods

Method Description
toggle Toggles the dropdown menu of a given navbar or tabbed navigation.
show Shows the dropdown menu of a given navbar or tabbed navigation.
hide Hides the dropdown menu of a given navbar or tabbed navigation.
update Updates the position of an element's dropdown.
dispose Destroys an element's dropdown. (Removes stored data on the DOM element)
getInstance Static method which allows you to get the dropdown instance associated with a DOM element.

Events

All dropdown events are fired at the .dropdown-menu’s parent element and have a relatedTarget property, whose value is the toggling anchor element. hide.bs.dropdown and hidden.bs.dropdown events have a clickEvent property (only when the original Event type is click) that contains an Event Object for the click event.

Method Description
show.bs.dropdown Fires immediately when the show instance method is called.
shown.bs.dropdown Fired when the dropdown has been made visible to the user and CSS transitions have completed.
hide.bs.dropdown Fires immediately when the hide instance method has been called.
hidden.bs.dropdown Fired when the dropdown has finished being hidden from the user and CSS transitions have completed.