2014-07-12 07:34:47 +02:00
---
2015-08-15 07:45:55 +02:00
layout: docs
2014-07-12 07:34:47 +02:00
title: Dropdowns
2016-10-03 03:19:47 +02:00
description: Toggle contextual overlays for displaying lists of links and more with the Bootstrap dropdown plugin.
2015-08-06 02:47:45 +02:00
group: components
2017-05-28 08:01:14 +02:00
toc: true
2014-07-12 07:34:47 +02:00
---
2017-04-18 14:02:24 +02:00
## Overview
2020-03-24 20:42:54 +01:00
Dropdowns are toggleable, contextual overlays for displaying lists of links and more. They're made interactive with the included Bootstrap dropdown JavaScript plugin. They're toggled by clicking, not by hovering; this is [an intentional design decision ](https://markdotto.com/2012/02/27/bootstrap-explained-dropdowns/ ).
2017-05-28 08:01:14 +02:00
2020-11-21 15:22:08 +01:00
Dropdowns are built on a third party library, [Popper ](https://popper.js.org/ ), which provides dynamic positioning and viewport detection. Be sure to include [popper.min.js ]({{< param "cdn.popper" >}} ) before Bootstrap's JavaScript or use `bootstrap.bundle.min.js` / `bootstrap.bundle.js` which contains Popper. Popper isn't used to position dropdowns in navbars though as dynamic positioning isn't required.
2017-04-18 14:02:24 +02:00
2017-05-30 22:59:33 +02:00
## Accessibility
2017-04-18 10:34:55 +02:00
2018-04-02 13:55:58 +02:00
The [<abbr title="Web Accessibility Initiative">WAI</abbr> <abbr title="Accessible Rich Internet Applications">ARIA</abbr> ](https://www.w3.org/TR/wai-aria/ ) standard defines an actual [`role="menu"` widget ](https://www.w3.org/WAI/PF/aria/roles#menu ), but this is specific to application-like menus which trigger actions or functions. < abbr title = "Accessible Rich Internet Applications" > ARIA</ abbr > menus can only contain menu items, checkbox menu items, radio button menu items, radio button groups, and sub-menus.
2017-04-18 10:34:55 +02:00
Bootstrap's dropdowns, on the other hand, are designed to be generic and applicable to a variety of situations and markup structures. For instance, it is possible to create dropdowns that contain additional inputs and form controls, such as search fields or login forms. For this reason, Bootstrap does not expect (nor automatically add) any of the `role` and `aria-` attributes required for true < abbr title = "Accessible Rich Internet Applications" > ARIA</ abbr > menus. Authors will have to include these more specific attributes themselves.
However, Bootstrap does add built-in support for most standard keyboard menu interactions, such as the ability to move through individual `.dropdown-item` elements using the cursor keys and close the menu with the < kbd > ESC</ kbd > key.
2017-05-30 22:59:33 +02:00
## Examples
2019-05-09 10:19:32 +02:00
Wrap the dropdown's toggle (your button or link) and the dropdown menu within `.dropdown` , or another element that declares `position: relative;` . Dropdowns can be triggered from `<a>` or `<button>` elements to better fit your potential needs. The examples shown here use semantic `<ul>` elements where appropriate, but custom markup is supported.
2017-04-18 10:34:55 +02:00
2018-01-22 07:40:55 +01:00
### Single button
2016-05-11 23:13:16 +02:00
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:
2014-07-12 07:34:47 +02:00
2019-01-08 17:33:28 +01:00
{{< example > }}
2017-01-04 04:24:24 +01:00
< div class = "dropdown" >
2021-02-05 23:57:43 +01:00
< button class = "btn btn-secondary dropdown-toggle" type = "button" id = "dropdownMenuButton1" data-bs-toggle = "dropdown" aria-expanded = "false" >
2016-05-11 23:13:16 +02:00
Dropdown button
2014-07-12 07:34:47 +02:00
< / button >
2021-02-05 23:57:43 +01:00
< ul class = "dropdown-menu" aria-labelledby = "dropdownMenuButton1" >
2019-05-09 10:19:32 +02:00
< li > < a class = "dropdown-item" href = "#" > Action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Another action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Something else here< / a > < / li >
< / ul >
2016-05-11 23:13:16 +02:00
< / div >
2019-01-08 17:33:28 +01:00
{{< / example > }}
2016-05-11 23:13:16 +02:00
And with `<a>` elements:
2019-01-08 17:33:28 +01:00
{{< example > }}
2018-02-11 01:12:15 +01:00
< div class = "dropdown" >
2020-07-22 21:33:11 +02:00
< a class = "btn btn-secondary dropdown-toggle" href = "#" role = "button" id = "dropdownMenuLink" data-bs-toggle = "dropdown" aria-expanded = "false" >
2016-05-11 23:13:16 +02:00
Dropdown link
< / a >
2019-05-09 10:19:32 +02:00
< ul class = "dropdown-menu" aria-labelledby = "dropdownMenuLink" >
< li > < a class = "dropdown-item" href = "#" > Action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Another action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Something else here< / a > < / li >
< / ul >
2014-07-12 07:34:47 +02:00
< / div >
2019-01-08 17:33:28 +01:00
{{< / example > }}
2014-07-12 07:34:47 +02:00
2016-05-11 23:13:16 +02:00
The best part is you can do this with any button variant, too:
< div class = "bd-example" >
< div class = "btn-group" >
2020-07-22 21:33:11 +02:00
< button type = "button" class = "btn btn-primary dropdown-toggle" data-bs-toggle = "dropdown" aria-expanded = "false" > Primary< / button >
2019-05-09 10:19:32 +02:00
< ul class = "dropdown-menu" >
< li > < a class = "dropdown-item" href = "#" > Action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Another action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Something else here< / a > < / li >
< li > < hr class = "dropdown-divider" > < / li >
< li > < a class = "dropdown-item" href = "#" > Separated link< / a > < / li >
< / ul >
2016-05-11 23:13:16 +02:00
< / div > <!-- /btn - group -->
< div class = "btn-group" >
2020-07-22 21:33:11 +02:00
< button type = "button" class = "btn btn-secondary dropdown-toggle" data-bs-toggle = "dropdown" aria-expanded = "false" > Secondary< / button >
2019-05-09 10:19:32 +02:00
< ul class = "dropdown-menu" >
< li > < a class = "dropdown-item" href = "#" > Action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Another action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Something else here< / a > < / li >
< li > < hr class = "dropdown-divider" > < / li >
< li > < a class = "dropdown-item" href = "#" > Separated link< / a > < / li >
< / ul >
2016-05-11 23:13:16 +02:00
< / div > <!-- /btn - group -->
< div class = "btn-group" >
2020-07-22 21:33:11 +02:00
< button type = "button" class = "btn btn-success dropdown-toggle" data-bs-toggle = "dropdown" aria-expanded = "false" > Success< / button >
2019-05-09 10:19:32 +02:00
< ul class = "dropdown-menu" >
< li > < a class = "dropdown-item" href = "#" > Action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Another action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Something else here< / a > < / li >
< li > < hr class = "dropdown-divider" > < / li >
< li > < a class = "dropdown-item" href = "#" > Separated link< / a > < / li >
< / ul >
2016-05-11 23:13:16 +02:00
< / div > <!-- /btn - group -->
< div class = "btn-group" >
2020-07-22 21:33:11 +02:00
< button type = "button" class = "btn btn-info dropdown-toggle" data-bs-toggle = "dropdown" aria-expanded = "false" > Info< / button >
2019-05-09 10:19:32 +02:00
< ul class = "dropdown-menu" >
< li > < a class = "dropdown-item" href = "#" > Action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Another action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Something else here< / a > < / li >
< li > < hr class = "dropdown-divider" > < / li >
< li > < a class = "dropdown-item" href = "#" > Separated link< / a > < / li >
< / ul >
2016-05-11 23:13:16 +02:00
< / div > <!-- /btn - group -->
< div class = "btn-group" >
2020-07-22 21:33:11 +02:00
< button type = "button" class = "btn btn-warning dropdown-toggle" data-bs-toggle = "dropdown" aria-expanded = "false" > Warning< / button >
2019-05-09 10:19:32 +02:00
< ul class = "dropdown-menu" >
< li > < a class = "dropdown-item" href = "#" > Action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Another action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Something else here< / a > < / li >
< li > < hr class = "dropdown-divider" > < / li >
< li > < a class = "dropdown-item" href = "#" > Separated link< / a > < / li >
< / ul >
2016-05-11 23:13:16 +02:00
< / div > <!-- /btn - group -->
< div class = "btn-group" >
2020-07-22 21:33:11 +02:00
< button type = "button" class = "btn btn-danger dropdown-toggle" data-bs-toggle = "dropdown" aria-expanded = "false" > Danger< / button >
2019-05-09 10:19:32 +02:00
< ul class = "dropdown-menu" >
< li > < a class = "dropdown-item" href = "#" > Action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Another action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Something else here< / a > < / li >
< li > < hr class = "dropdown-divider" > < / li >
< li > < a class = "dropdown-item" href = "#" > Separated link< / a > < / li >
< / ul >
2016-05-11 23:13:16 +02:00
< / div > <!-- /btn - group -->
< / div >
2020-10-19 11:56:49 +02:00
```html
2016-05-11 23:13:16 +02:00
<!-- Example single danger button -->
< div class = "btn-group" >
2020-07-22 21:33:11 +02:00
< button type = "button" class = "btn btn-danger dropdown-toggle" data-bs-toggle = "dropdown" aria-expanded = "false" >
2016-05-11 23:13:16 +02:00
Action
< / button >
2019-05-09 10:19:32 +02:00
< ul class = "dropdown-menu" >
< li > < a class = "dropdown-item" href = "#" > Action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Another action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Something else here< / a > < / li >
< li > < hr class = "dropdown-divider" > < / li >
< li > < a class = "dropdown-item" href = "#" > Separated link< / a > < / li >
< / ul >
2016-05-11 23:13:16 +02:00
< / div >
2020-10-19 11:56:49 +02:00
```
2016-05-11 23:13:16 +02:00
2018-01-22 07:40:55 +01:00
### Split button
2016-05-11 23:13:16 +02:00
Similarly, create split button dropdowns with virtually the same markup as single button dropdowns, but with the addition of `.dropdown-toggle-split` for proper spacing around the dropdown caret.
We use this extra class to reduce the horizontal `padding` on either side of the caret by 25% and remove the `margin-left` that's added for regular button dropdowns. Those extra changes keep the caret centered in the split button and provide a more appropriately sized hit area next to the main button.
< div class = "bd-example" >
< div class = "btn-group" >
2016-10-27 10:12:14 +02:00
< button type = "button" class = "btn btn-primary" > Primary< / button >
2020-07-22 21:33:11 +02:00
< button type = "button" class = "btn btn-primary dropdown-toggle dropdown-toggle-split" data-bs-toggle = "dropdown" aria-expanded = "false" >
2020-07-03 13:38:11 +02:00
< span class = "visually-hidden" > Toggle Dropdown< / span >
2016-05-11 23:13:16 +02:00
< / button >
2019-05-09 10:19:32 +02:00
< ul class = "dropdown-menu" >
< li > < a class = "dropdown-item" href = "#" > Action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Another action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Something else here< / a > < / li >
< li > < hr class = "dropdown-divider" > < / li >
< li > < a class = "dropdown-item" href = "#" > Separated link< / a > < / li >
< / ul >
2016-05-11 23:13:16 +02:00
< / div > <!-- /btn - group -->
< div class = "btn-group" >
2016-10-27 10:12:14 +02:00
< button type = "button" class = "btn btn-secondary" > Secondary< / button >
2020-07-22 21:33:11 +02:00
< button type = "button" class = "btn btn-secondary dropdown-toggle dropdown-toggle-split" data-bs-toggle = "dropdown" aria-expanded = "false" >
2020-07-03 13:38:11 +02:00
< span class = "visually-hidden" > Toggle Dropdown< / span >
2016-05-11 23:13:16 +02:00
< / button >
2019-05-09 10:19:32 +02:00
< ul class = "dropdown-menu" >
< li > < a class = "dropdown-item" href = "#" > Action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Another action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Something else here< / a > < / li >
< li > < hr class = "dropdown-divider" > < / li >
< li > < a class = "dropdown-item" href = "#" > Separated link< / a > < / li >
< / ul >
2016-05-11 23:13:16 +02:00
< / div > <!-- /btn - group -->
< div class = "btn-group" >
< button type = "button" class = "btn btn-success" > Success< / button >
2020-07-22 21:33:11 +02:00
< button type = "button" class = "btn btn-success dropdown-toggle dropdown-toggle-split" data-bs-toggle = "dropdown" aria-expanded = "false" >
2020-07-03 13:38:11 +02:00
< span class = "visually-hidden" > Toggle Dropdown< / span >
2016-05-11 23:13:16 +02:00
< / button >
2019-05-09 10:19:32 +02:00
< ul class = "dropdown-menu" >
< li > < a class = "dropdown-item" href = "#" > Action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Another action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Something else here< / a > < / li >
< li > < hr class = "dropdown-divider" > < / li >
< li > < a class = "dropdown-item" href = "#" > Separated link< / a > < / li >
< / ul >
2016-05-11 23:13:16 +02:00
< / div > <!-- /btn - group -->
< div class = "btn-group" >
< button type = "button" class = "btn btn-info" > Info< / button >
2020-07-22 21:33:11 +02:00
< button type = "button" class = "btn btn-info dropdown-toggle dropdown-toggle-split" data-bs-toggle = "dropdown" aria-expanded = "false" >
2020-07-03 13:38:11 +02:00
< span class = "visually-hidden" > Toggle Dropdown< / span >
2016-05-11 23:13:16 +02:00
< / button >
2019-05-09 10:19:32 +02:00
< ul class = "dropdown-menu" >
< li > < a class = "dropdown-item" href = "#" > Action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Another action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Something else here< / a > < / li >
< li > < hr class = "dropdown-divider" > < / li >
< li > < a class = "dropdown-item" href = "#" > Separated link< / a > < / li >
< / ul >
2016-05-11 23:13:16 +02:00
< / div > <!-- /btn - group -->
< div class = "btn-group" >
< button type = "button" class = "btn btn-warning" > Warning< / button >
2020-07-22 21:33:11 +02:00
< button type = "button" class = "btn btn-warning dropdown-toggle dropdown-toggle-split" data-bs-toggle = "dropdown" aria-expanded = "false" >
2020-07-03 13:38:11 +02:00
< span class = "visually-hidden" > Toggle Dropdown< / span >
2016-05-11 23:13:16 +02:00
< / button >
2019-05-09 10:19:32 +02:00
< ul class = "dropdown-menu" >
< li > < a class = "dropdown-item" href = "#" > Action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Another action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Something else here< / a > < / li >
< li > < hr class = "dropdown-divider" > < / li >
< li > < a class = "dropdown-item" href = "#" > Separated link< / a > < / li >
< / ul >
2016-05-11 23:13:16 +02:00
< / div > <!-- /btn - group -->
< div class = "btn-group" >
< button type = "button" class = "btn btn-danger" > Danger< / button >
2020-07-22 21:33:11 +02:00
< button type = "button" class = "btn btn-danger dropdown-toggle dropdown-toggle-split" data-bs-toggle = "dropdown" aria-expanded = "false" >
2020-07-03 13:38:11 +02:00
< span class = "visually-hidden" > Toggle Dropdown< / span >
2016-05-11 23:13:16 +02:00
< / button >
2019-05-09 10:19:32 +02:00
< ul class = "dropdown-menu" >
< li > < a class = "dropdown-item" href = "#" > Action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Another action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Something else here< / a > < / li >
< li > < hr class = "dropdown-divider" > < / li >
< li > < a class = "dropdown-item" href = "#" > Separated link< / a > < / li >
< / ul >
2016-05-11 23:13:16 +02:00
< / div > <!-- /btn - group -->
< / div >
2020-10-19 11:56:49 +02:00
```html
2016-05-11 23:13:16 +02:00
<!-- Example split danger button -->
< div class = "btn-group" >
< button type = "button" class = "btn btn-danger" > Action< / button >
2020-07-22 21:33:11 +02:00
< button type = "button" class = "btn btn-danger dropdown-toggle dropdown-toggle-split" data-bs-toggle = "dropdown" aria-expanded = "false" >
2020-07-03 13:38:11 +02:00
< span class = "visually-hidden" > Toggle Dropdown< / span >
2016-05-11 23:13:16 +02:00
< / button >
2019-05-09 10:19:32 +02:00
< ul class = "dropdown-menu" >
< li > < a class = "dropdown-item" href = "#" > Action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Another action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Something else here< / a > < / li >
< li > < hr class = "dropdown-divider" > < / li >
< li > < a class = "dropdown-item" href = "#" > Separated link< / a > < / li >
< / ul >
2016-05-11 23:13:16 +02:00
< / div >
2020-10-19 11:56:49 +02:00
```
2016-05-11 23:13:16 +02:00
## Sizing
Button dropdowns work with buttons of all sizes, including default and split dropdown buttons.
< div class = "bd-example" >
2020-10-13 14:14:55 +02:00
< div class = "btn-group" >
2020-07-22 21:33:11 +02:00
< button class = "btn btn-secondary btn-lg dropdown-toggle" type = "button" data-bs-toggle = "dropdown" aria-expanded = "false" >
2020-10-13 14:14:55 +02:00
Large button
< / button >
< ul class = "dropdown-menu" >
< li > < a class = "dropdown-item" href = "#" > Action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Another action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Something else here< / a > < / li >
< li > < hr class = "dropdown-divider" > < / li >
< li > < a class = "dropdown-item" href = "#" > Separated link< / a > < / li >
< / ul >
< / div >
< div class = "btn-group" >
< button type = "button" class = "btn btn-lg btn-secondary" > Large split button< / button >
2020-07-22 21:33:11 +02:00
< button type = "button" class = "btn btn-lg btn-secondary dropdown-toggle dropdown-toggle-split" data-bs-toggle = "dropdown" aria-expanded = "false" >
2020-10-13 14:14:55 +02:00
< span class = "visually-hidden" > Toggle Dropdown< / span >
< / button >
< ul class = "dropdown-menu" >
< li > < a class = "dropdown-item" href = "#" > Action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Another action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Something else here< / a > < / li >
< li > < hr class = "dropdown-divider" > < / li >
< li > < a class = "dropdown-item" href = "#" > Separated link< / a > < / li >
< / ul >
< / div >
2019-01-28 21:36:26 +01:00
< / div >
2016-05-11 23:13:16 +02:00
2020-10-19 11:56:49 +02:00
```html
2016-05-11 23:13:16 +02:00
<!-- Large button groups (default and split) -->
< div class = "btn-group" >
2020-07-22 21:33:11 +02:00
< button class = "btn btn-secondary btn-lg dropdown-toggle" type = "button" data-bs-toggle = "dropdown" aria-expanded = "false" >
2016-05-11 23:13:16 +02:00
Large button
< / button >
2019-05-09 10:19:32 +02:00
< ul class = "dropdown-menu" >
2016-05-11 23:13:16 +02:00
...
2019-05-09 10:19:32 +02:00
< / ul >
2016-05-11 23:13:16 +02:00
< / div >
< div class = "btn-group" >
2017-05-24 16:32:36 +02:00
< button class = "btn btn-secondary btn-lg" type = "button" >
2018-01-15 05:08:33 +01:00
Large split button
2016-05-11 23:13:16 +02:00
< / button >
2020-07-22 21:33:11 +02:00
< button type = "button" class = "btn btn-lg btn-secondary dropdown-toggle dropdown-toggle-split" data-bs-toggle = "dropdown" aria-expanded = "false" >
2020-07-03 13:38:11 +02:00
< span class = "visually-hidden" > Toggle Dropdown< / span >
2016-05-11 23:13:16 +02:00
< / button >
2019-05-09 10:19:32 +02:00
< ul class = "dropdown-menu" >
2016-05-11 23:13:16 +02:00
...
2019-05-09 10:19:32 +02:00
< / ul >
2016-05-11 23:13:16 +02:00
< / div >
2020-10-19 11:56:49 +02:00
```
2016-05-11 23:13:16 +02:00
2020-10-13 14:14:55 +02:00
< div class = "bd-example" >
< div class = "btn-group" >
2020-07-22 21:33:11 +02:00
< button class = "btn btn-secondary btn-sm dropdown-toggle" type = "button" data-bs-toggle = "dropdown" aria-expanded = "false" >
2020-10-13 14:14:55 +02:00
Small button
< / button >
< ul class = "dropdown-menu" >
< li > < a class = "dropdown-item" href = "#" > Action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Another action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Something else here< / a > < / li >
< li > < hr class = "dropdown-divider" > < / li >
< li > < a class = "dropdown-item" href = "#" > Separated link< / a > < / li >
< / ul >
< / div >
< div class = "btn-group" >
< button type = "button" class = "btn btn-sm btn-secondary" > Small split button< / button >
2020-07-22 21:33:11 +02:00
< button type = "button" class = "btn btn-sm btn-secondary dropdown-toggle dropdown-toggle-split" data-bs-toggle = "dropdown" aria-expanded = "false" >
2020-10-13 14:14:55 +02:00
< span class = "visually-hidden" > Toggle Dropdown< / span >
< / button >
< ul class = "dropdown-menu" >
< li > < a class = "dropdown-item" href = "#" > Action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Another action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Something else here< / a > < / li >
< li > < hr class = "dropdown-divider" > < / li >
< li > < a class = "dropdown-item" href = "#" > Separated link< / a > < / li >
< / ul >
< / div >
< / div >
2020-10-29 18:05:39 +01:00
```html
2016-05-11 23:13:16 +02:00
< div class = "btn-group" >
2020-07-22 21:33:11 +02:00
< button class = "btn btn-secondary btn-sm dropdown-toggle" type = "button" data-bs-toggle = "dropdown" aria-expanded = "false" >
2016-05-11 23:13:16 +02:00
Small button
< / button >
2019-05-09 10:19:32 +02:00
< ul class = "dropdown-menu" >
2016-05-11 23:13:16 +02:00
...
2019-05-09 10:19:32 +02:00
< / ul >
2016-05-11 23:13:16 +02:00
< / div >
< div class = "btn-group" >
2017-05-24 16:32:36 +02:00
< button class = "btn btn-secondary btn-sm" type = "button" >
2018-01-15 05:08:33 +01:00
Small split button
2016-05-11 23:13:16 +02:00
< / button >
2020-07-22 21:33:11 +02:00
< button type = "button" class = "btn btn-sm btn-secondary dropdown-toggle dropdown-toggle-split" data-bs-toggle = "dropdown" aria-expanded = "false" >
2020-07-03 13:38:11 +02:00
< span class = "visually-hidden" > Toggle Dropdown< / span >
2016-05-11 23:13:16 +02:00
< / button >
2019-05-09 10:19:32 +02:00
< ul class = "dropdown-menu" >
2016-05-11 23:13:16 +02:00
...
2019-05-09 10:19:32 +02:00
< / ul >
2016-05-11 23:13:16 +02:00
< / div >
2020-10-19 11:56:49 +02:00
```
2016-05-11 23:13:16 +02:00
2020-09-24 17:55:15 +02:00
## Dark dropdowns
Opt into darker dropdowns to match a dark navbar or custom style by adding `.dropdown-menu-dark` onto an existing `.dropdown-menu` . No changes are required to the dropdown items.
{{< example > }}
< div class = "dropdown" >
2020-07-22 21:33:11 +02:00
< button class = "btn btn-secondary dropdown-toggle" type = "button" id = "dropdownMenuButton2" data-bs-toggle = "dropdown" aria-expanded = "false" >
2020-09-24 17:55:15 +02:00
Dropdown button
< / button >
< ul class = "dropdown-menu dropdown-menu-dark" aria-labelledby = "dropdownMenuButton2" >
< li > < a class = "dropdown-item active" href = "#" > Action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Another action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Something else here< / a > < / li >
< li > < hr class = "dropdown-divider" > < / li >
< li > < a class = "dropdown-item" href = "#" > Separated link< / a > < / li >
< / ul >
< / div >
{{< / example > }}
And putting it to use in a navbar:
{{< example > }}
< nav class = "navbar navbar-expand-lg navbar-dark bg-dark" >
< div class = "container-fluid" >
< a class = "navbar-brand" href = "#" > Navbar< / a >
2020-07-22 21:33:11 +02:00
< button class = "navbar-toggler" type = "button" data-bs-toggle = "collapse" data-bs-target = "#navbarNavDarkDropdown" aria-controls = "navbarNavDarkDropdown" aria-expanded = "false" aria-label = "Toggle navigation" >
2020-09-24 17:55:15 +02:00
< span class = "navbar-toggler-icon" > < / span >
< / button >
< div class = "collapse navbar-collapse" id = "navbarNavDarkDropdown" >
< ul class = "navbar-nav" >
< li class = "nav-item dropdown" >
2020-07-22 21:33:11 +02:00
< a class = "nav-link dropdown-toggle" href = "#" id = "navbarDarkDropdownMenuLink" role = "button" data-bs-toggle = "dropdown" aria-expanded = "false" >
2020-09-24 17:55:15 +02:00
Dropdown
< / a >
< ul class = "dropdown-menu dropdown-menu-dark" aria-labelledby = "navbarDarkDropdownMenuLink" >
< li > < a class = "dropdown-item" href = "#" > Action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Another action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Something else here< / a > < / li >
< / ul >
< / li >
< / ul >
< / div >
< / div >
< / nav >
{{< / example > }}
2018-01-22 07:40:55 +01:00
## Directions
2020-06-09 15:44:20 +02:00
{{< callout info > }}
#### RTL
Directions are mirrored when using Bootstrap in RTL, meaning `.dropstart` will appear on the right side.
{{< / callout > }}
2018-01-22 07:40:55 +01:00
### Dropup
2016-05-11 23:13:16 +02:00
Trigger dropdown menus above elements by adding `.dropup` to the parent element.
< div class = "bd-example" >
2017-01-04 04:24:24 +01:00
< div class = "btn-group dropup" >
2020-07-22 21:33:11 +02:00
< button type = "button" class = "btn btn-secondary dropdown-toggle" data-bs-toggle = "dropdown" aria-expanded = "false" >
2017-01-04 04:24:24 +01:00
Dropup
< / button >
2019-05-09 10:19:32 +02:00
< ul class = "dropdown-menu" >
< li > < a class = "dropdown-item" href = "#" > Action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Another action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Something else here< / a > < / li >
< li > < hr class = "dropdown-divider" > < / li >
< li > < a class = "dropdown-item" href = "#" > Separated link< / a > < / li >
< / ul >
2017-01-04 04:24:24 +01:00
< / div >
< div class = "btn-group dropup" >
< button type = "button" class = "btn btn-secondary" >
Split dropup
< / button >
2020-07-22 21:33:11 +02:00
< button type = "button" class = "btn btn-secondary dropdown-toggle dropdown-toggle-split" data-bs-toggle = "dropdown" aria-expanded = "false" >
2020-07-03 13:38:11 +02:00
< span class = "visually-hidden" > Toggle Dropdown< / span >
2017-01-04 04:24:24 +01:00
< / button >
2019-05-09 10:19:32 +02:00
< ul class = "dropdown-menu" >
< li > < a class = "dropdown-item" href = "#" > Action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Another action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Something else here< / a > < / li >
< li > < hr class = "dropdown-divider" > < / li >
< li > < a class = "dropdown-item" href = "#" > Separated link< / a > < / li >
< / ul >
2016-05-11 23:13:16 +02:00
< / div >
< / div >
2020-10-19 11:56:49 +02:00
```html
2016-05-11 23:13:16 +02:00
<!-- Default dropup button -->
< div class = "btn-group dropup" >
2020-07-22 21:33:11 +02:00
< button type = "button" class = "btn btn-secondary dropdown-toggle" data-bs-toggle = "dropdown" aria-expanded = "false" >
2017-11-20 01:28:30 +01:00
Dropup
2016-05-11 23:13:16 +02:00
< / button >
2019-05-09 10:19:32 +02:00
< ul class = "dropdown-menu" >
2016-05-11 23:13:16 +02:00
<!-- Dropdown menu links -->
2019-05-09 10:19:32 +02:00
< / ul >
2016-05-11 23:13:16 +02:00
< / div >
<!-- Split dropup button -->
< div class = "btn-group dropup" >
< button type = "button" class = "btn btn-secondary" >
Split dropup
< / button >
2020-07-22 21:33:11 +02:00
< button type = "button" class = "btn btn-secondary dropdown-toggle dropdown-toggle-split" data-bs-toggle = "dropdown" aria-expanded = "false" >
2020-07-03 13:38:11 +02:00
< span class = "visually-hidden" > Toggle Dropdown< / span >
2016-05-11 23:13:16 +02:00
< / button >
2019-05-09 10:19:32 +02:00
< ul class = "dropdown-menu" >
2016-05-11 23:13:16 +02:00
<!-- Dropdown menu links -->
2019-05-09 10:19:32 +02:00
< / ul >
2016-05-11 23:13:16 +02:00
< / div >
2020-10-19 11:56:49 +02:00
```
2016-05-11 23:13:16 +02:00
2018-01-22 07:40:55 +01:00
### Dropright
2017-10-29 23:29:13 +01:00
2020-06-09 15:44:20 +02:00
Trigger dropdown menus at the right of the elements by adding `.dropend` to the parent element.
2017-10-29 23:29:13 +01:00
< div class = "bd-example" >
2020-06-09 15:44:20 +02:00
< div class = "btn-group dropend" >
2020-07-22 21:33:11 +02:00
< button type = "button" class = "btn btn-secondary dropdown-toggle" data-bs-toggle = "dropdown" aria-expanded = "false" >
2017-10-29 23:29:13 +01:00
Dropright
< / button >
2019-05-09 10:19:32 +02:00
< ul class = "dropdown-menu" >
< li > < a class = "dropdown-item" href = "#" > Action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Another action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Something else here< / a > < / li >
< li > < hr class = "dropdown-divider" > < / li >
< li > < a class = "dropdown-item" href = "#" > Separated link< / a > < / li >
< / ul >
2017-10-29 23:29:13 +01:00
< / div >
2020-06-09 15:44:20 +02:00
< div class = "btn-group dropend" >
2017-10-29 23:29:13 +01:00
< button type = "button" class = "btn btn-secondary" >
2020-06-09 15:44:20 +02:00
Split dropend
2017-10-29 23:29:13 +01:00
< / button >
2020-07-22 21:33:11 +02:00
< button type = "button" class = "btn btn-secondary dropdown-toggle dropdown-toggle-split" data-bs-toggle = "dropdown" aria-expanded = "false" >
2020-07-03 13:38:11 +02:00
< span class = "visually-hidden" > Toggle Dropright< / span >
2017-10-29 23:29:13 +01:00
< / button >
2019-05-09 10:19:32 +02:00
< ul class = "dropdown-menu" >
< li > < a class = "dropdown-item" href = "#" > Action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Another action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Something else here< / a > < / li >
< li > < hr class = "dropdown-divider" > < / li >
< li > < a class = "dropdown-item" href = "#" > Separated link< / a > < / li >
< / ul >
2017-10-29 23:29:13 +01:00
< / div >
< / div >
2020-10-19 11:56:49 +02:00
```html
2020-06-09 15:44:20 +02:00
<!-- Default dropend button -->
< div class = "btn-group dropend" >
2020-07-22 21:33:11 +02:00
< button type = "button" class = "btn btn-secondary dropdown-toggle" data-bs-toggle = "dropdown" aria-expanded = "false" >
2018-01-15 05:08:33 +01:00
Dropright
2017-10-29 23:29:13 +01:00
< / button >
2019-05-09 10:19:32 +02:00
< ul class = "dropdown-menu" >
2017-10-29 23:29:13 +01:00
<!-- Dropdown menu links -->
2019-05-09 10:19:32 +02:00
< / ul >
2017-10-29 23:29:13 +01:00
< / div >
2020-06-09 15:44:20 +02:00
<!-- Split dropend button -->
< div class = "btn-group dropend" >
2017-10-29 23:29:13 +01:00
< button type = "button" class = "btn btn-secondary" >
2020-06-09 15:44:20 +02:00
Split dropend
2017-10-29 23:29:13 +01:00
< / button >
2020-07-22 21:33:11 +02:00
< button type = "button" class = "btn btn-secondary dropdown-toggle dropdown-toggle-split" data-bs-toggle = "dropdown" aria-expanded = "false" >
2020-07-03 13:38:11 +02:00
< span class = "visually-hidden" > Toggle Dropright< / span >
2017-10-29 23:29:13 +01:00
< / button >
2019-05-09 10:19:32 +02:00
< ul class = "dropdown-menu" >
2017-10-29 23:29:13 +01:00
<!-- Dropdown menu links -->
2019-05-09 10:19:32 +02:00
< / ul >
2017-10-29 23:29:13 +01:00
< / div >
2020-10-19 11:56:49 +02:00
```
2017-10-29 23:29:13 +01:00
2018-01-22 07:40:55 +01:00
### Dropleft
2017-10-29 23:29:13 +01:00
2020-06-09 15:44:20 +02:00
Trigger dropdown menus at the left of the elements by adding `.dropstart` to the parent element.
2017-10-29 23:29:13 +01:00
< div class = "bd-example" >
2020-06-09 15:44:20 +02:00
< div class = "btn-group dropstart" >
2020-07-22 21:33:11 +02:00
< button type = "button" class = "btn btn-secondary dropdown-toggle" data-bs-toggle = "dropdown" aria-expanded = "false" >
2017-10-29 23:29:13 +01:00
Dropleft
< / button >
2019-05-09 10:19:32 +02:00
< ul class = "dropdown-menu" >
< li > < a class = "dropdown-item" href = "#" > Action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Another action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Something else here< / a > < / li >
< li > < hr class = "dropdown-divider" > < / li >
< li > < a class = "dropdown-item" href = "#" > Separated link< / a > < / li >
< / ul >
2017-10-29 23:29:13 +01:00
< / div >
< div class = "btn-group" >
2020-06-09 15:44:20 +02:00
< div class = "btn-group dropstart" role = "group" >
2020-07-22 21:33:11 +02:00
< button type = "button" class = "btn btn-secondary dropdown-toggle dropdown-toggle-split" data-bs-toggle = "dropdown" aria-expanded = "false" >
2020-07-03 13:38:11 +02:00
< span class = "visually-hidden" > Toggle Dropleft< / span >
2017-10-29 23:29:13 +01:00
< / button >
2019-05-09 10:19:32 +02:00
< ul class = "dropdown-menu" >
< li > < a class = "dropdown-item" href = "#" > Action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Another action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Something else here< / a > < / li >
< li > < hr class = "dropdown-divider" > < / li >
< li > < a class = "dropdown-item" href = "#" > Separated link< / a > < / li >
< / ul >
2017-10-29 23:29:13 +01:00
< / div >
< button type = "button" class = "btn btn-secondary" >
2020-06-09 15:44:20 +02:00
Split dropstart
2017-10-29 23:29:13 +01:00
< / button >
< / div >
< / div >
2020-10-19 11:56:49 +02:00
```html
2020-06-09 15:44:20 +02:00
<!-- Default dropstart button -->
< div class = "btn-group dropstart" >
2020-07-22 21:33:11 +02:00
< button type = "button" class = "btn btn-secondary dropdown-toggle" data-bs-toggle = "dropdown" aria-expanded = "false" >
2020-06-09 15:44:20 +02:00
Dropstart
2017-10-29 23:29:13 +01:00
< / button >
2019-05-09 10:19:32 +02:00
< ul class = "dropdown-menu" >
2017-10-29 23:29:13 +01:00
<!-- Dropdown menu links -->
2019-05-09 10:19:32 +02:00
< / ul >
2017-10-29 23:29:13 +01:00
< / div >
2020-06-09 15:44:20 +02:00
<!-- Split dropstart button -->
2017-10-29 23:29:13 +01:00
< div class = "btn-group" >
2020-06-09 15:44:20 +02:00
< div class = "btn-group dropstart" role = "group" >
2020-07-22 21:33:11 +02:00
< button type = "button" class = "btn btn-secondary dropdown-toggle dropdown-toggle-split" data-bs-toggle = "dropdown" aria-expanded = "false" >
2020-06-09 15:44:20 +02:00
< span class = "visually-hidden" > Toggle Dropstart< / span >
2017-10-29 23:29:13 +01:00
< / button >
2019-05-09 10:19:32 +02:00
< ul class = "dropdown-menu" >
2017-10-29 23:29:13 +01:00
<!-- Dropdown menu links -->
2019-05-09 10:19:32 +02:00
< / ul >
2017-10-29 23:29:13 +01:00
< / div >
< button type = "button" class = "btn btn-secondary" >
2020-06-09 15:44:20 +02:00
Split dropstart
2017-10-29 23:29:13 +01:00
< / button >
< / div >
2020-10-19 11:56:49 +02:00
```
2017-10-29 23:29:13 +01:00
2016-05-11 23:13:16 +02:00
## Menu items
2015-08-18 03:18:37 +02:00
2016-05-11 23:13:16 +02:00
Historically dropdown menu contents *had* to be links, but that's no longer the case with v4. Now you can optionally use `<button>` elements in your dropdowns instead of just `<a>` s.
2015-08-18 03:18:37 +02:00
2019-01-08 17:33:28 +01:00
{{< example > }}
2017-01-04 04:24:24 +01:00
< div class = "dropdown" >
2020-07-22 21:33:11 +02:00
< button class = "btn btn-secondary dropdown-toggle" type = "button" id = "dropdownMenu2" data-bs-toggle = "dropdown" aria-expanded = "false" >
2015-08-18 03:18:37 +02:00
Dropdown
< / button >
2019-05-09 10:19:32 +02:00
< ul class = "dropdown-menu" aria-labelledby = "dropdownMenu2" >
< li > < button class = "dropdown-item" type = "button" > Action< / button > < / li >
< li > < button class = "dropdown-item" type = "button" > Another action< / button > < / li >
< li > < button class = "dropdown-item" type = "button" > Something else here< / button > < / li >
< / ul >
2015-08-18 03:18:37 +02:00
< / div >
2019-01-08 17:33:28 +01:00
{{< / example > }}
2015-08-18 03:18:37 +02:00
2018-01-22 07:40:55 +01:00
You can also create non-interactive dropdown items with `.dropdown-item-text` . Feel free to style further with custom CSS or text utilities.
2019-01-08 17:33:28 +01:00
{{< example > }}
2019-05-09 10:19:32 +02:00
< ul class = "dropdown-menu" >
< li > < span class = "dropdown-item-text" > Dropdown item text< / span > < / li >
< li > < a class = "dropdown-item" href = "#" > Action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Another action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Something else here< / a > < / li >
< / ul >
2019-01-08 17:33:28 +01:00
{{< / example > }}
2018-01-22 07:40:55 +01:00
### Active
2020-02-07 12:18:30 +01:00
Add `.active` to items in the dropdown to **style them as active** . To convey the active state to assistive technologies, use the `aria-current` attribute — using the `page` value for the current page, or `true` for the current item in a set.
2018-01-22 07:40:55 +01:00
2019-01-08 17:33:28 +01:00
{{< example > }}
2019-05-09 10:19:32 +02:00
< ul class = "dropdown-menu" >
< li > < a class = "dropdown-item" href = "#" > Regular link< / a > < / li >
2020-02-07 12:18:30 +01:00
< li > < a class = "dropdown-item active" href = "#" aria-current = "true" > Active link< / a > < / li >
2019-05-09 10:19:32 +02:00
< li > < a class = "dropdown-item" href = "#" > Another link< / a > < / li >
< / ul >
2019-01-08 17:33:28 +01:00
{{< / example > }}
2018-01-22 07:40:55 +01:00
### Disabled
Add `.disabled` to items in the dropdown to **style them as disabled** .
2019-01-08 17:33:28 +01:00
{{< example > }}
2019-05-09 10:19:32 +02:00
< ul class = "dropdown-menu" >
< li > < a class = "dropdown-item" href = "#" > Regular link< / a > < / li >
< li > < a class = "dropdown-item disabled" href = "#" tabindex = "-1" aria-disabled = "true" > Disabled link< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Another link< / a > < / li >
< / ul >
2019-01-08 17:33:28 +01:00
{{< / example > }}
2018-01-22 07:40:55 +01:00
2016-05-11 23:13:16 +02:00
## Menu alignment
2014-07-12 07:34:47 +02:00
2021-02-05 23:57:43 +01:00
By default, a dropdown menu is automatically positioned 100% from the top and along the left side of its parent. You can change this with the directional `.drop*` classes, but you can also control them with additional modifier classes.
Add `.dropdown-menu-end` to a `.dropdown-menu` to right align the dropdown menu. Directions are mirrored when using Bootstrap in RTL, meaning `.dropdown-menu-end` will appear on the left side.
2014-07-12 07:34:47 +02:00
2020-10-13 15:37:21 +02:00
{{< callout info > }}
2021-02-05 23:57:43 +01:00
**Heads up!** Dropdowns are positioned thanks to Popper except when they are contained in a navbar.
2020-10-13 15:37:21 +02:00
{{< / callout > }}
2014-07-12 07:34:47 +02:00
2019-01-08 17:33:28 +01:00
{{< example > }}
2016-01-11 01:02:33 +01:00
< div class = "btn-group" >
2020-07-22 21:33:11 +02:00
< button type = "button" class = "btn btn-secondary dropdown-toggle" data-bs-toggle = "dropdown" aria-expanded = "false" >
2020-11-09 21:04:31 +01:00
Right-aligned menu example
2016-01-11 01:02:33 +01:00
< / button >
2020-06-09 15:44:20 +02:00
< ul class = "dropdown-menu dropdown-menu-end" >
2019-05-09 10:19:32 +02:00
< li > < button class = "dropdown-item" type = "button" > Action< / button > < / li >
< li > < button class = "dropdown-item" type = "button" > Another action< / button > < / li >
< li > < button class = "dropdown-item" type = "button" > Something else here< / button > < / li >
< / ul >
2015-08-17 20:19:14 +02:00
< / div >
2019-01-08 17:33:28 +01:00
{{< / example > }}
2014-07-12 07:34:47 +02:00
2018-10-21 10:01:22 +02:00
### Responsive alignment
2020-07-22 21:33:11 +02:00
If you want to use responsive alignment, disable dynamic positioning by adding the `data-bs-display="static"` attribute and use the responsive variation classes.
2018-10-21 10:01:22 +02:00
2020-06-09 15:44:20 +02:00
To align **right** the dropdown menu with the given breakpoint or larger, add `.dropdown-menu{-sm|-md|-lg|-xl|-xxl}-end` .
2018-10-21 10:01:22 +02:00
2019-01-08 17:33:28 +01:00
{{< example > }}
2018-10-21 10:01:22 +02:00
< div class = "btn-group" >
2020-07-22 21:33:11 +02:00
< button type = "button" class = "btn btn-secondary dropdown-toggle" data-bs-toggle = "dropdown" data-bs-display = "static" aria-expanded = "false" >
2018-10-21 10:01:22 +02:00
Left-aligned but right aligned when large screen
< / button >
2020-06-09 15:44:20 +02:00
< ul class = "dropdown-menu dropdown-menu-lg-end" >
2019-05-09 10:19:32 +02:00
< li > < button class = "dropdown-item" type = "button" > Action< / button > < / li >
< li > < button class = "dropdown-item" type = "button" > Another action< / button > < / li >
< li > < button class = "dropdown-item" type = "button" > Something else here< / button > < / li >
< / ul >
2018-10-21 10:01:22 +02:00
< / div >
2019-01-08 17:33:28 +01:00
{{< / example > }}
2018-10-21 10:01:22 +02:00
2020-06-09 15:44:20 +02:00
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` .
2018-10-21 10:01:22 +02:00
2019-01-08 17:33:28 +01:00
{{< example > }}
2018-10-21 10:01:22 +02:00
< div class = "btn-group" >
2020-07-22 21:33:11 +02:00
< button type = "button" class = "btn btn-secondary dropdown-toggle" data-bs-toggle = "dropdown" data-bs-display = "static" aria-expanded = "false" >
2018-10-21 10:01:22 +02:00
Right-aligned but left aligned when large screen
< / button >
2020-06-09 15:44:20 +02:00
< ul class = "dropdown-menu dropdown-menu-end dropdown-menu-lg-start" >
2019-05-09 10:19:32 +02:00
< li > < button class = "dropdown-item" type = "button" > Action< / button > < / li >
< li > < button class = "dropdown-item" type = "button" > Another action< / button > < / li >
< li > < button class = "dropdown-item" type = "button" > Something else here< / button > < / li >
< / ul >
2018-10-21 10:01:22 +02:00
< / div >
2019-01-08 17:33:28 +01:00
{{< / example > }}
2018-10-21 10:01:22 +02:00
2020-11-21 15:22:08 +01:00
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.
2018-10-21 10:01:22 +02:00
2021-02-05 23:57:43 +01:00
### Alignment options
Taking most of the options shown above, here's a small kitchen sink demo of various dropdown alignment options in one place.
{{< example > }}
< div class = "btn-group" >
< button class = "btn btn-secondary dropdown-toggle" type = "button" id = "dropdownMenuButton" data-bs-toggle = "dropdown" aria-expanded = "false" >
Dropdown
< / button >
< ul class = "dropdown-menu" aria-labelledby = "dropdownMenuButton" >
< li > < a class = "dropdown-item" href = "#" > Menu item< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Menu item< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Menu item< / a > < / li >
< / ul >
< / div >
< div class = "btn-group" >
< button type = "button" class = "btn btn-secondary dropdown-toggle" data-bs-toggle = "dropdown" aria-expanded = "false" >
Right-aligned menu
< / button >
< ul class = "dropdown-menu dropdown-menu-end" >
< li > < a class = "dropdown-item" href = "#" > Menu item< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Menu item< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Menu item< / a > < / li >
< / ul >
< / div >
< div class = "btn-group" >
< button type = "button" class = "btn btn-secondary dropdown-toggle" data-bs-toggle = "dropdown" data-bs-display = "static" aria-expanded = "false" >
Left-aligned, right-aligned lg
< / button >
< ul class = "dropdown-menu dropdown-menu-lg-end" >
< li > < a class = "dropdown-item" href = "#" > Menu item< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Menu item< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Menu item< / a > < / li >
< / ul >
< / div >
< div class = "btn-group" >
< button type = "button" class = "btn btn-secondary dropdown-toggle" data-bs-toggle = "dropdown" data-bs-display = "static" aria-expanded = "false" >
Right-aligned, left-aligned lg
< / button >
< ul class = "dropdown-menu dropdown-menu-end dropdown-menu-lg-start" >
< li > < a class = "dropdown-item" href = "#" > Menu item< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Menu item< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Menu item< / a > < / li >
< / ul >
< / div >
< div class = "btn-group dropstart" >
< button type = "button" class = "btn btn-secondary dropdown-toggle" data-bs-toggle = "dropdown" aria-expanded = "false" >
Dropstart
< / button >
< ul class = "dropdown-menu" >
< li > < a class = "dropdown-item" href = "#" > Menu item< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Menu item< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Menu item< / a > < / li >
< / ul >
< / div >
< div class = "btn-group dropend" >
< button type = "button" class = "btn btn-secondary dropdown-toggle" data-bs-toggle = "dropdown" aria-expanded = "false" >
Dropend
< / button >
< ul class = "dropdown-menu" >
< li > < a class = "dropdown-item" href = "#" > Menu item< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Menu item< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Menu item< / a > < / li >
< / ul >
< / div >
< div class = "btn-group dropup" >
< button type = "button" class = "btn btn-secondary dropdown-toggle" data-bs-toggle = "dropdown" aria-expanded = "false" >
Dropup
< / button >
< ul class = "dropdown-menu" >
< li > < a class = "dropdown-item" href = "#" > Menu item< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Menu item< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Menu item< / a > < / li >
< / ul >
< / div >
{{< / example > }}
2018-01-22 07:40:55 +01:00
## Menu content
### Headers
2014-07-12 07:34:47 +02:00
Add a header to label sections of actions in any dropdown menu.
2019-01-08 17:33:28 +01:00
{{< example > }}
2019-05-09 10:19:32 +02:00
< ul class = "dropdown-menu" >
< li > < h6 class = "dropdown-header" > Dropdown header< / h6 > < / li >
< li > < a class = "dropdown-item" href = "#" > Action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Another action< / a > < / li >
< / ul >
2019-01-08 17:33:28 +01:00
{{< / example > }}
2014-07-12 07:34:47 +02:00
2018-01-22 07:40:55 +01:00
### Dividers
2014-07-12 07:34:47 +02:00
Separate groups of related menu items with a divider.
2019-01-08 17:33:28 +01:00
{{< example > }}
2019-05-09 10:19:32 +02:00
< ul class = "dropdown-menu" >
< li > < a class = "dropdown-item" href = "#" > Action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Another action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Something else here< / a > < / li >
< li > < hr class = "dropdown-divider" > < / li >
< li > < a class = "dropdown-item" href = "#" > Separated link< / a > < / li >
< / ul >
2019-01-08 17:33:28 +01:00
{{< / example > }}
2014-07-12 07:34:47 +02:00
2018-01-22 07:40:55 +01:00
### Text
2019-02-04 11:22:02 +01:00
Place any freeform text within a dropdown menu with text and use [spacing utilities ]({{< docsref "/utilities/spacing" >}} ). Note that you'll likely need additional sizing styles to constrain the menu width.
2018-01-22 07:40:55 +01:00
2019-01-08 17:33:28 +01:00
{{< example > }}
2018-01-22 07:40:55 +01:00
< div class = "dropdown-menu p-4 text-muted" style = "max-width: 200px;" >
< p >
Some example text that's free-flowing within the dropdown menu.
< / p >
< p class = "mb-0" >
And this is more example text.
< / p >
< / div >
2019-01-08 17:33:28 +01:00
{{< / example > }}
2018-01-22 07:40:55 +01:00
### Forms
2017-06-18 05:56:26 +02:00
2019-02-04 11:22:02 +01:00
Put a form within a dropdown menu, or make it into a dropdown menu, and use [margin or padding utilities ]({{< docsref "/utilities/spacing" >}} ) to give it the negative space you require.
2017-06-18 05:56:26 +02:00
2019-01-08 17:33:28 +01:00
{{< example > }}
2017-06-18 05:56:26 +02:00
< div class = "dropdown-menu" >
< form class = "px-4 py-3" >
2019-08-29 22:07:55 +02:00
< div class = "mb-3" >
2020-03-31 20:02:57 +02:00
< label for = "exampleDropdownFormEmail1" class = "form-label" > Email address< / label >
2017-06-18 05:56:26 +02:00
< input type = "email" class = "form-control" id = "exampleDropdownFormEmail1" placeholder = "email@example.com" >
< / div >
2019-08-29 22:07:55 +02:00
< div class = "mb-3" >
2020-03-31 20:02:57 +02:00
< label for = "exampleDropdownFormPassword1" class = "form-label" > Password< / label >
2017-06-18 05:56:26 +02:00
< input type = "password" class = "form-control" id = "exampleDropdownFormPassword1" placeholder = "Password" >
< / div >
2019-08-29 22:07:55 +02:00
< div class = "mb-3" >
2018-11-07 21:54:40 +01:00
< div class = "form-check" >
< input type = "checkbox" class = "form-check-input" id = "dropdownCheck" >
< label class = "form-check-label" for = "dropdownCheck" >
Remember me
< / label >
< / div >
2017-06-18 05:56:26 +02:00
< / div >
< button type = "submit" class = "btn btn-primary" > Sign in< / button >
< / form >
< div class = "dropdown-divider" > < / div >
< a class = "dropdown-item" href = "#" > New around here? Sign up< / a >
< a class = "dropdown-item" href = "#" > Forgot password?< / a >
< / div >
2019-01-08 17:33:28 +01:00
{{< / example > }}
2017-06-18 05:56:26 +02:00
2019-01-08 17:33:28 +01:00
{{< example > }}
2017-06-18 05:56:26 +02:00
< form class = "dropdown-menu p-4" >
2019-08-29 22:07:55 +02:00
< div class = "mb-3" >
2020-03-31 20:02:57 +02:00
< label for = "exampleDropdownFormEmail2" class = "form-label" > Email address< / label >
2017-06-18 05:56:26 +02:00
< input type = "email" class = "form-control" id = "exampleDropdownFormEmail2" placeholder = "email@example.com" >
< / div >
2019-08-29 22:07:55 +02:00
< div class = "mb-3" >
2020-03-31 20:02:57 +02:00
< label for = "exampleDropdownFormPassword2" class = "form-label" > Password< / label >
2017-08-11 11:43:17 +02:00
< input type = "password" class = "form-control" id = "exampleDropdownFormPassword2" placeholder = "Password" >
2017-06-18 05:56:26 +02:00
< / div >
2019-08-29 22:07:55 +02:00
< div class = "mb-3" >
2018-11-07 21:54:40 +01:00
< div class = "form-check" >
< input type = "checkbox" class = "form-check-input" id = "dropdownCheck2" >
< label class = "form-check-label" for = "dropdownCheck2" >
Remember me
< / label >
< / div >
2017-06-18 05:56:26 +02:00
< / div >
< button type = "submit" class = "btn btn-primary" > Sign in< / button >
< / form >
2019-01-08 17:33:28 +01:00
{{< / example > }}
2017-06-18 05:56:26 +02:00
2018-01-21 19:09:23 +01:00
## Dropdown options
2020-07-22 21:33:11 +02:00
Use `data-bs-offset` or `data-bs-reference` to change the location of the dropdown.
2018-01-21 19:09:23 +01:00
2019-01-08 17:33:28 +01:00
{{< example > }}
2018-01-21 19:09:23 +01:00
< div class = "d-flex" >
2020-06-09 15:44:20 +02:00
< div class = "dropdown me-1" >
2020-07-22 21:33:11 +02:00
< button type = "button" class = "btn btn-secondary dropdown-toggle" id = "dropdownMenuOffset" data-bs-toggle = "dropdown" aria-expanded = "false" data-bs-offset = "10,20" >
2018-01-21 19:09:23 +01:00
Offset
< / button >
2019-05-09 10:19:32 +02:00
< ul class = "dropdown-menu" aria-labelledby = "dropdownMenuOffset" >
< li > < a class = "dropdown-item" href = "#" > Action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Another action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Something else here< / a > < / li >
< / ul >
2018-01-21 19:09:23 +01:00
< / div >
< div class = "btn-group" >
< button type = "button" class = "btn btn-secondary" > Reference< / button >
2020-07-22 21:33:11 +02:00
< button type = "button" class = "btn btn-secondary dropdown-toggle dropdown-toggle-split" id = "dropdownMenuReference" data-bs-toggle = "dropdown" aria-expanded = "false" data-bs-reference = "parent" >
2020-07-03 13:38:11 +02:00
< span class = "visually-hidden" > Toggle Dropdown< / span >
2018-01-21 19:09:23 +01:00
< / button >
2019-05-09 10:19:32 +02:00
< ul class = "dropdown-menu" aria-labelledby = "dropdownMenuReference" >
< li > < a class = "dropdown-item" href = "#" > Action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Another action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Something else here< / a > < / li >
< li > < hr class = "dropdown-divider" > < / li >
< li > < a class = "dropdown-item" href = "#" > Separated link< / a > < / li >
< / ul >
2018-01-21 19:09:23 +01:00
< / div >
< / div >
2019-01-08 17:33:28 +01:00
{{< / example > }}
2018-01-21 19:09:23 +01:00
2021-02-11 04:29:59 +01:00
## Sass
### Variables
Variables for all dropdowns:
{{< scss-docs name = "dropdown-variables" file = "scss/_variables.scss" > }}
Variables for the [dark dropdown ](#dark-dropdowns ):
{{< scss-docs name = "dropdown-dark-variables" file = "scss/_variables.scss" > }}
Variables for the CSS-based carets that indicate a dropdown's interactivity:
{{< scss-docs name = "caret-variables" file = "scss/_variables.scss" > }}
### Mixins
Mixins are used to generate the CSS-based carets and can be found in `scss/mixins/_caret.scss` .
{{< scss-docs name = "caret-mixins" file = "scss/mixins/_caret.scss" > }}
2015-03-31 03:23:35 +02:00
## Usage
2020-11-18 11:50:55 +01:00
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.
2015-03-31 03:23:35 +02:00
2020-10-13 15:37:21 +02:00
{{< callout info > }}
2019-05-14 11:50:10 +02:00
On touch-enabled devices, opening a dropdown adds empty `mouseover` handlers to the immediate children of the `<body>` 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.
2020-10-13 15:37:21 +02:00
{{< / callout > }}
2015-03-31 03:23:35 +02:00
### Via data attributes
2020-07-22 21:33:11 +02:00
Add `data-bs-toggle="dropdown"` to a link or button to toggle a dropdown.
2015-03-31 03:23:35 +02:00
2020-10-19 11:56:49 +02:00
```html
2015-03-31 03:23:35 +02:00
< div class = "dropdown" >
2020-07-22 21:33:11 +02:00
< button id = "dLabel" type = "button" data-bs-toggle = "dropdown" aria-expanded = "false" >
2015-03-31 03:23:35 +02:00
Dropdown trigger
< / button >
2019-05-09 10:19:32 +02:00
< ul class = "dropdown-menu" aria-labelledby = "dLabel" >
2015-03-31 03:23:35 +02:00
...
2019-05-09 10:19:32 +02:00
< / ul >
2015-03-31 03:23:35 +02:00
< / div >
2020-10-19 11:56:49 +02:00
```
2015-03-31 03:23:35 +02:00
### Via JavaScript
Call the dropdowns via JavaScript:
2020-10-19 11:56:49 +02:00
```js
2019-05-14 11:50:10 +02:00
var dropdownElementList = [].slice.call(document.querySelectorAll('.dropdown-toggle'))
var dropdownList = dropdownElementList.map(function (dropdownToggleEl) {
return new bootstrap.Dropdown(dropdownToggleEl)
})
2020-10-19 11:56:49 +02:00
```
2015-03-31 03:23:35 +02:00
2020-10-13 15:37:21 +02:00
{{< callout info > }}
2020-07-22 21:33:11 +02:00
##### `data-bs-toggle="dropdown"` still required
2015-04-17 01:56:40 +02:00
2020-07-22 21:33:11 +02:00
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.
2020-10-13 15:37:21 +02:00
{{< / callout > }}
2015-03-31 03:23:35 +02:00
### Options
2020-07-22 21:33:11 +02:00
Options can be passed via data attributes or JavaScript. For data attributes, append the option name to `data-bs-` , as in `data-bs-offset=""` .
2017-04-18 14:02:24 +02:00
v5: Forms update (#28450)
* Initial spike of consolidated form checks
* Stub out forms rearrangement
- Prepping to drop non-custom file and range inputs
- Prepping to merge custom and native checks and radios (with switches)
- Prepping to merge custom select with form select
- Moving docs arround so forms has it's own area given volume of CSS
* Move input group Sass file to forms subdir
* Start to split and move the docs around
* Simpler imports
* Copyediting
* delete overview file
* Remove commented out code
* remove the custom-forms import
* rewrite flex-check as form-check, replace all custom properties
* Remove old forms doc
* stub out new subpage link section
* update migration guide
* Update nav, forms overview in page nav, and descriptions
* fix check bg position
* fix margin-top calculation
* rename .custom-select to .form-select
* Update validation styles for new checks
* add some vertical margin, fix inline checks
* fix docs examples
* better way to do this contents stuff, redo the toc while i'm at it
* page restyle for docs while here
* un-callout that, edit text
* redo padding on toc
* fix toc
* start to cleanup checks docs
* Rewrite Markdown tables into HTML
* Redesign tables, redo their docs
* Replace Open Iconic icons with custom Bootstrap icons
* Redesign the docs navbar, add a subheader, redo the sidebar
* Redesign docs homepage a bit
* Simplify table style overrides for docs tables
* Simplify docs typography for page titles and reading line length
* Stub out icons page
* Part of sidebar update, remove migration from nav.yml
* Move toc CSS to separate partial
* Change appearance of overview page
* fix sidebar arrow direction
* Add footer to docs layout
* Update descriptions
* Drop the .form-group class for margin utilities
* Remove lingering form-group-margin-bottom var
* improve footer spacing
* add headings to range page
* uncomment form range css
* Rename .custom-range to .form-range
* Drop unused docs var
* Uncomment the comment
* Remove unused variable
* Fix radio image sizing
* Reboot update: reset horizontal ul and ol padding
* de-dupe IDs
* tweak toc styles
* nvm, fix dropdown versions stuff
* remove sidebar nav toggle for now
* broken html
* fix more broken html, move css
* scss linting
* comment out broken helper docs
* scope styles
* scope styles
* Fixes #25540 and fixes #26407 for v5 only
* Update sidebar once more
* Match new sidenav order
* fix syntax error
* Rename custom-file to form-file, update paths, update migration docs for previous changes in #28696
* rename back
* fix size and alignment
* rename that back too
2019-07-12 23:52:33 +02:00
< table class = "table" >
2017-04-18 14:02:24 +02:00
< thead >
< tr >
< th style = "width: 100px;" > Name< / th >
< th style = "width: 100px;" > Type< / th >
< th style = "width: 50px;" > Default< / th >
< th > Description< / th >
< / tr >
< / thead >
< tbody >
2017-12-12 10:28:30 +01:00
< tr >
2020-06-27 13:28:21 +02:00
< td > < code > boundary< / code > < / td >
2017-12-12 10:28:30 +01:00
< td > string | element< / td >
2021-02-04 06:26:32 +01:00
< td > < code > 'clippingParents'< / code > < / td >
2020-06-19 10:17:01 +02:00
< td > Overflow constraint boundary of the dropdown menu. By default it's < code > 'clippingParents'< / code > and can accept an HTMLElement reference (JavaScript only). For more information refer to Popper's < a href = "https://popper.js.org/docs/v2/utils/detect-overflow/#boundary" > preventOverflow docs< / a > .< / td >
2017-12-12 10:28:30 +01:00
< / tr >
2018-01-21 19:09:23 +01:00
< tr >
2020-06-27 13:28:21 +02:00
< td > < code > reference< / code > < / td >
2020-12-21 13:32:11 +01:00
< td > string | element | object< / td >
2020-06-27 13:28:21 +02:00
< td > < code > 'toggle'< / code > < / td >
2020-12-21 13:32:11 +01:00
< td > Reference element of the dropdown menu. Accepts the values of < code > 'toggle'< / code > , < code > 'parent'< / code > , an HTMLElement reference or an object providing < code > getBoundingClientRect< / code > . For more information refer to Popper's < a href = "https://popper.js.org/docs/v2/constructors/#createpopper" > constructor docs< / a > and < a href = "https://popper.js.org/docs/v2/virtual-elements/" > virtual element docs< / a > .< / td >
2018-01-21 19:09:23 +01:00
< / tr >
2018-02-12 01:45:59 +01:00
< tr >
2020-06-27 13:28:21 +02:00
< td > < code > display< / code > < / td >
2018-02-12 01:45:59 +01:00
< td > string< / td >
2020-06-27 13:28:21 +02:00
< td > < code > 'dynamic'< / code > < / td >
2020-11-21 15:22:08 +01:00
< td > By default, we use Popper for dynamic positioning. Disable this with < code > static< / code > .< / td >
2018-02-12 01:45:59 +01:00
< / tr >
2020-12-12 01:54:29 +01:00
< tr >
< td > < code > offset< / code > < / td >
< td > array | string | function< / td >
2021-02-03 20:37:25 +01:00
< td > < code > [0, 2]< / code > < / td >
2020-12-12 01:54:29 +01:00
< td >
2020-12-18 09:00:36 +01:00
< p > Offset of the dropdown relative to its target. You can pass a string in data attributes with comma separated values like: < code > data-bs-offset="10,20"< / code > < / p >
< p > When a function is used to determine the offset, it is called with an object containing the popper placement, the reference, and popper rects as its first argument. The triggering element DOM node is passed as the second argument. The function must return an array with two numbers: < code > [< a href = "https://popper.js.org/docs/v2/modifiers/offset/#skidding-1" > skidding< / a > , < a href = "https://popper.js.org/docs/v2/modifiers/offset/#distance-1" > distance< / a > ]< / code > .< / p >
< p > For more information refer to Popper's < a href = "https://popper.js.org/docs/v2/modifiers/offset/#options" > offset docs< / a > .< / p >
2020-12-12 01:54:29 +01:00
< / td >
< / tr >
2019-08-14 17:27:58 +02:00
< tr >
2020-06-27 13:28:21 +02:00
< td > < code > popperConfig< / code > < / td >
2021-02-09 20:16:13 +01:00
< td > null | object | function< / td >
2020-06-27 13:28:21 +02:00
< td > < code > null< / code > < / td >
2021-02-09 20:16:13 +01:00
< td >
< p > To change Bootstrap's default Popper config, see < a href = "https://popper.js.org/docs/v2/constructors/#options" > Popper's configuration< / a > .< / p >
< p > When a function is used to create the Popper configuration, it's called with an object that contains the Bootstrap's default Popper configuration. It helps you use and merge the default with your own configuration. The function must return a configuration object for Popper.< / p >
< / td >
2019-08-14 17:27:58 +02:00
< / tr >
2017-04-18 14:02:24 +02:00
< / tbody >
< / table >
2015-03-31 03:23:35 +02:00
2021-02-09 20:16:13 +01:00
#### Using function with `popperConfig`
```js
var dropdown = new bootstrap.Dropdown(element, {
popperConfig: function (defaultBsPopperConfig) {
// var newPopperConfig = {...}
// use defaultBsPopperConfig if needed...
// return newPopperConfig
}
})
```
2015-03-31 03:23:35 +02:00
### Methods
2019-07-15 18:59:55 +02:00
< table class = "table" >
v5: Forms update (#28450)
* Initial spike of consolidated form checks
* Stub out forms rearrangement
- Prepping to drop non-custom file and range inputs
- Prepping to merge custom and native checks and radios (with switches)
- Prepping to merge custom select with form select
- Moving docs arround so forms has it's own area given volume of CSS
* Move input group Sass file to forms subdir
* Start to split and move the docs around
* Simpler imports
* Copyediting
* delete overview file
* Remove commented out code
* remove the custom-forms import
* rewrite flex-check as form-check, replace all custom properties
* Remove old forms doc
* stub out new subpage link section
* update migration guide
* Update nav, forms overview in page nav, and descriptions
* fix check bg position
* fix margin-top calculation
* rename .custom-select to .form-select
* Update validation styles for new checks
* add some vertical margin, fix inline checks
* fix docs examples
* better way to do this contents stuff, redo the toc while i'm at it
* page restyle for docs while here
* un-callout that, edit text
* redo padding on toc
* fix toc
* start to cleanup checks docs
* Rewrite Markdown tables into HTML
* Redesign tables, redo their docs
* Replace Open Iconic icons with custom Bootstrap icons
* Redesign the docs navbar, add a subheader, redo the sidebar
* Redesign docs homepage a bit
* Simplify table style overrides for docs tables
* Simplify docs typography for page titles and reading line length
* Stub out icons page
* Part of sidebar update, remove migration from nav.yml
* Move toc CSS to separate partial
* Change appearance of overview page
* fix sidebar arrow direction
* Add footer to docs layout
* Update descriptions
* Drop the .form-group class for margin utilities
* Remove lingering form-group-margin-bottom var
* improve footer spacing
* add headings to range page
* uncomment form range css
* Rename .custom-range to .form-range
* Drop unused docs var
* Uncomment the comment
* Remove unused variable
* Fix radio image sizing
* Reboot update: reset horizontal ul and ol padding
* de-dupe IDs
* tweak toc styles
* nvm, fix dropdown versions stuff
* remove sidebar nav toggle for now
* broken html
* fix more broken html, move css
* scss linting
* comment out broken helper docs
* scope styles
* scope styles
* Fixes #25540 and fixes #26407 for v5 only
* Update sidebar once more
* Match new sidenav order
* fix syntax error
* Rename custom-file to form-file, update paths, update migration docs for previous changes in #28696
* rename back
* fix size and alignment
* rename that back too
2019-07-12 23:52:33 +02:00
< thead >
< tr >
< th > Method< / th >
< th > Description< / th >
< / tr >
< / thead >
< tbody >
< tr >
< td > < code > toggle< / code > < / td >
< td >
Toggles the dropdown menu of a given navbar or tabbed navigation.
< / td >
< / tr >
< tr >
< td > < code > show< / code > < / td >
< td >
Shows the dropdown menu of a given navbar or tabbed navigation.
< / td >
< / tr >
< tr >
< td > < code > hide< / code > < / td >
< td >
Hides the dropdown menu of a given navbar or tabbed navigation.
< / td >
< / tr >
< tr >
< td > < code > update< / code > < / td >
< td >
Updates the position of an element's dropdown.
< / td >
< / tr >
< tr >
< td > < code > dispose< / code > < / td >
< td >
2020-10-02 13:58:59 +02:00
Destroys an element's dropdown. (Removes stored data on the DOM element)
v5: Forms update (#28450)
* Initial spike of consolidated form checks
* Stub out forms rearrangement
- Prepping to drop non-custom file and range inputs
- Prepping to merge custom and native checks and radios (with switches)
- Prepping to merge custom select with form select
- Moving docs arround so forms has it's own area given volume of CSS
* Move input group Sass file to forms subdir
* Start to split and move the docs around
* Simpler imports
* Copyediting
* delete overview file
* Remove commented out code
* remove the custom-forms import
* rewrite flex-check as form-check, replace all custom properties
* Remove old forms doc
* stub out new subpage link section
* update migration guide
* Update nav, forms overview in page nav, and descriptions
* fix check bg position
* fix margin-top calculation
* rename .custom-select to .form-select
* Update validation styles for new checks
* add some vertical margin, fix inline checks
* fix docs examples
* better way to do this contents stuff, redo the toc while i'm at it
* page restyle for docs while here
* un-callout that, edit text
* redo padding on toc
* fix toc
* start to cleanup checks docs
* Rewrite Markdown tables into HTML
* Redesign tables, redo their docs
* Replace Open Iconic icons with custom Bootstrap icons
* Redesign the docs navbar, add a subheader, redo the sidebar
* Redesign docs homepage a bit
* Simplify table style overrides for docs tables
* Simplify docs typography for page titles and reading line length
* Stub out icons page
* Part of sidebar update, remove migration from nav.yml
* Move toc CSS to separate partial
* Change appearance of overview page
* fix sidebar arrow direction
* Add footer to docs layout
* Update descriptions
* Drop the .form-group class for margin utilities
* Remove lingering form-group-margin-bottom var
* improve footer spacing
* add headings to range page
* uncomment form range css
* Rename .custom-range to .form-range
* Drop unused docs var
* Uncomment the comment
* Remove unused variable
* Fix radio image sizing
* Reboot update: reset horizontal ul and ol padding
* de-dupe IDs
* tweak toc styles
* nvm, fix dropdown versions stuff
* remove sidebar nav toggle for now
* broken html
* fix more broken html, move css
* scss linting
* comment out broken helper docs
* scope styles
* scope styles
* Fixes #25540 and fixes #26407 for v5 only
* Update sidebar once more
* Match new sidenav order
* fix syntax error
* Rename custom-file to form-file, update paths, update migration docs for previous changes in #28696
* rename back
* fix size and alignment
* rename that back too
2019-07-12 23:52:33 +02:00
< / td >
< / tr >
< tr >
2019-07-28 15:24:46 +02:00
< td > < code > getInstance< / code > < / td >
v5: Forms update (#28450)
* Initial spike of consolidated form checks
* Stub out forms rearrangement
- Prepping to drop non-custom file and range inputs
- Prepping to merge custom and native checks and radios (with switches)
- Prepping to merge custom select with form select
- Moving docs arround so forms has it's own area given volume of CSS
* Move input group Sass file to forms subdir
* Start to split and move the docs around
* Simpler imports
* Copyediting
* delete overview file
* Remove commented out code
* remove the custom-forms import
* rewrite flex-check as form-check, replace all custom properties
* Remove old forms doc
* stub out new subpage link section
* update migration guide
* Update nav, forms overview in page nav, and descriptions
* fix check bg position
* fix margin-top calculation
* rename .custom-select to .form-select
* Update validation styles for new checks
* add some vertical margin, fix inline checks
* fix docs examples
* better way to do this contents stuff, redo the toc while i'm at it
* page restyle for docs while here
* un-callout that, edit text
* redo padding on toc
* fix toc
* start to cleanup checks docs
* Rewrite Markdown tables into HTML
* Redesign tables, redo their docs
* Replace Open Iconic icons with custom Bootstrap icons
* Redesign the docs navbar, add a subheader, redo the sidebar
* Redesign docs homepage a bit
* Simplify table style overrides for docs tables
* Simplify docs typography for page titles and reading line length
* Stub out icons page
* Part of sidebar update, remove migration from nav.yml
* Move toc CSS to separate partial
* Change appearance of overview page
* fix sidebar arrow direction
* Add footer to docs layout
* Update descriptions
* Drop the .form-group class for margin utilities
* Remove lingering form-group-margin-bottom var
* improve footer spacing
* add headings to range page
* uncomment form range css
* Rename .custom-range to .form-range
* Drop unused docs var
* Uncomment the comment
* Remove unused variable
* Fix radio image sizing
* Reboot update: reset horizontal ul and ol padding
* de-dupe IDs
* tweak toc styles
* nvm, fix dropdown versions stuff
* remove sidebar nav toggle for now
* broken html
* fix more broken html, move css
* scss linting
* comment out broken helper docs
* scope styles
* scope styles
* Fixes #25540 and fixes #26407 for v5 only
* Update sidebar once more
* Match new sidenav order
* fix syntax error
* Rename custom-file to form-file, update paths, update migration docs for previous changes in #28696
* rename back
* fix size and alignment
* rename that back too
2019-07-12 23:52:33 +02:00
< td >
Static method which allows you to get the dropdown instance associated with a DOM element.
< / td >
< / tr >
< / tbody >
< / table >
2015-03-31 03:23:35 +02:00
### Events
2021-02-03 20:51:19 +01:00
All dropdown events are fired at the toggling element and then bubbled up. So you can also add event listeners on the `.dropdown-menu` 's parent 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.
v5: Forms update (#28450)
* Initial spike of consolidated form checks
* Stub out forms rearrangement
- Prepping to drop non-custom file and range inputs
- Prepping to merge custom and native checks and radios (with switches)
- Prepping to merge custom select with form select
- Moving docs arround so forms has it's own area given volume of CSS
* Move input group Sass file to forms subdir
* Start to split and move the docs around
* Simpler imports
* Copyediting
* delete overview file
* Remove commented out code
* remove the custom-forms import
* rewrite flex-check as form-check, replace all custom properties
* Remove old forms doc
* stub out new subpage link section
* update migration guide
* Update nav, forms overview in page nav, and descriptions
* fix check bg position
* fix margin-top calculation
* rename .custom-select to .form-select
* Update validation styles for new checks
* add some vertical margin, fix inline checks
* fix docs examples
* better way to do this contents stuff, redo the toc while i'm at it
* page restyle for docs while here
* un-callout that, edit text
* redo padding on toc
* fix toc
* start to cleanup checks docs
* Rewrite Markdown tables into HTML
* Redesign tables, redo their docs
* Replace Open Iconic icons with custom Bootstrap icons
* Redesign the docs navbar, add a subheader, redo the sidebar
* Redesign docs homepage a bit
* Simplify table style overrides for docs tables
* Simplify docs typography for page titles and reading line length
* Stub out icons page
* Part of sidebar update, remove migration from nav.yml
* Move toc CSS to separate partial
* Change appearance of overview page
* fix sidebar arrow direction
* Add footer to docs layout
* Update descriptions
* Drop the .form-group class for margin utilities
* Remove lingering form-group-margin-bottom var
* improve footer spacing
* add headings to range page
* uncomment form range css
* Rename .custom-range to .form-range
* Drop unused docs var
* Uncomment the comment
* Remove unused variable
* Fix radio image sizing
* Reboot update: reset horizontal ul and ol padding
* de-dupe IDs
* tweak toc styles
* nvm, fix dropdown versions stuff
* remove sidebar nav toggle for now
* broken html
* fix more broken html, move css
* scss linting
* comment out broken helper docs
* scope styles
* scope styles
* Fixes #25540 and fixes #26407 for v5 only
* Update sidebar once more
* Match new sidenav order
* fix syntax error
* Rename custom-file to form-file, update paths, update migration docs for previous changes in #28696
* rename back
* fix size and alignment
* rename that back too
2019-07-12 23:52:33 +02:00
2019-07-15 18:59:55 +02:00
< table class = "table" >
v5: Forms update (#28450)
* Initial spike of consolidated form checks
* Stub out forms rearrangement
- Prepping to drop non-custom file and range inputs
- Prepping to merge custom and native checks and radios (with switches)
- Prepping to merge custom select with form select
- Moving docs arround so forms has it's own area given volume of CSS
* Move input group Sass file to forms subdir
* Start to split and move the docs around
* Simpler imports
* Copyediting
* delete overview file
* Remove commented out code
* remove the custom-forms import
* rewrite flex-check as form-check, replace all custom properties
* Remove old forms doc
* stub out new subpage link section
* update migration guide
* Update nav, forms overview in page nav, and descriptions
* fix check bg position
* fix margin-top calculation
* rename .custom-select to .form-select
* Update validation styles for new checks
* add some vertical margin, fix inline checks
* fix docs examples
* better way to do this contents stuff, redo the toc while i'm at it
* page restyle for docs while here
* un-callout that, edit text
* redo padding on toc
* fix toc
* start to cleanup checks docs
* Rewrite Markdown tables into HTML
* Redesign tables, redo their docs
* Replace Open Iconic icons with custom Bootstrap icons
* Redesign the docs navbar, add a subheader, redo the sidebar
* Redesign docs homepage a bit
* Simplify table style overrides for docs tables
* Simplify docs typography for page titles and reading line length
* Stub out icons page
* Part of sidebar update, remove migration from nav.yml
* Move toc CSS to separate partial
* Change appearance of overview page
* fix sidebar arrow direction
* Add footer to docs layout
* Update descriptions
* Drop the .form-group class for margin utilities
* Remove lingering form-group-margin-bottom var
* improve footer spacing
* add headings to range page
* uncomment form range css
* Rename .custom-range to .form-range
* Drop unused docs var
* Uncomment the comment
* Remove unused variable
* Fix radio image sizing
* Reboot update: reset horizontal ul and ol padding
* de-dupe IDs
* tweak toc styles
* nvm, fix dropdown versions stuff
* remove sidebar nav toggle for now
* broken html
* fix more broken html, move css
* scss linting
* comment out broken helper docs
* scope styles
* scope styles
* Fixes #25540 and fixes #26407 for v5 only
* Update sidebar once more
* Match new sidenav order
* fix syntax error
* Rename custom-file to form-file, update paths, update migration docs for previous changes in #28696
* rename back
* fix size and alignment
* rename that back too
2019-07-12 23:52:33 +02:00
< thead >
< tr >
< th > Method< / th >
< th > Description< / th >
< / tr >
< / thead >
< tbody >
< tr >
< td >
< code > show.bs.dropdown< / code >
< / td >
< td >
Fires immediately when the show instance method is called.
< / td >
< / tr >
< tr >
< td >
< code > shown.bs.dropdown< / code >
< / td >
< td >
Fired when the dropdown has been made visible to the user and CSS transitions have completed.
< / td >
< / tr >
< tr >
< td >
< code > hide.bs.dropdown< / code >
< / td >
< td >
Fires immediately when the hide instance method has been called.
< / td >
< / tr >
< tr >
< td >
< code > hidden.bs.dropdown< / code >
< / td >
< td >
Fired when the dropdown has finished being hidden from the user and CSS transitions have completed.
< / td >
< / tr >
< / tbody >
< / table >
2015-03-31 03:23:35 +02:00
2020-10-19 11:56:49 +02:00
```js
2019-05-14 11:50:10 +02:00
var myDropdown = document.getElementById('myDropdown')
myDropdown.addEventListener('show.bs.dropdown', function () {
2019-02-10 21:25:51 +01:00
// do something...
2015-03-31 03:23:35 +02:00
})
2020-10-19 11:56:49 +02:00
```