Menu

Source: https://getbootstrap.com/docs/6.0/components/menu

Toggle contextual menus and custom overlays for lists of buttons, links, forms, and other custom content.

Overview

Toggle menus with buttons whenever possible. Here’s an example using a Bootstrap button:

Toggle menu </button> <div class="menu"> <a class="menu-item" href="#">Menu item 1</a> <a class="menu-item" href="#">Menu item 2</a> <a class="menu-item" href="#">Menu item 3</a> </div>`} />

Menus are toggleable, contextual overlays for displaying lists of links and more. They’re made interactive with the included Bootstrap menu JavaScript plugin. They’re toggled by clicking, not by hovering; this is an intentional design decision.

Menus are built on a third party library, Floating UI, which provides dynamic positioning and viewport detection. Use bootstrap.bundle.min.js / bootstrap.bundle.js which includes Floating UI, or include Floating UI separately via an import map. Floating UI isn’t used to position menus in navbars though as dynamic positioning isn’t required.

Examples

While <button> is the recommended control for a menu toggle, there might be situations where you have to use an <a> element. If you do, we recommend adding a role="button" attribute to appropriately convey control’s purpose to assistive technologies such as screen readers.

Use button groups to create split button menus where the menu is displayed when a secondary button is clicked.

Toggle menu </a> <div class="menu"> <a class="menu-item" href="#">Menu item 1</a> <a class="menu-item" href="#">Menu item 2</a> <a class="menu-item" href="#">Menu item 3</a> </div>

<div class="btn-group"> <button type="button" class="btn-solid theme-secondary">Split</button> <button type="button" class="btn-solid theme-secondary menu-toggle-split" data-bs-toggle="menu" aria-expanded="false"> <svg class="bi" width="16" height="16" aria-hidden="true"><use href="#chevron-expand" /></svg> <span class="visually-hidden">Toggle menu</span> </button> <div class="menu"> <a class="menu-item" href="#">Action</a> <a class="menu-item" href="#">Another action</a> <a class="menu-item" href="#">Something else here</a> <hr class="menu-divider"> <a class="menu-item" href="#">Separated link</a> </div> </div>`} />

Dark menus

Opt into darker menus to match a dark navbar or custom style by adding data-bs-theme="dark" onto the toggle element or a parent.

<button class="btn-solid theme-secondary" type="button" data-bs-toggle="menu" aria-expanded="false"> Menu button </button> <div class="menu"> <a class="menu-item active" href="#">Action</a> <a class="menu-item" href="#">Another action</a> <a class="menu-item" href="#">Something else here</a> <hr class="menu-divider"> <a class="menu-item" href="#">Separated link</a> </div> </div>`} />

And putting it to use in a navbar:

<div class="container-fluid"> <a class="navbar-brand" href="#">Navbar</a> <ul class="navbar-nav"> <li class="nav-item" data-bs-theme="dark"> <button class="btn-solid theme-secondary" data-bs-toggle="menu" aria-expanded="false"> Menu </button> <div class="menu"> <a class="menu-item" href="#">Action</a> <a class="menu-item" href="#">Another action</a> <a class="menu-item" href="#">Something else here</a> </div> </li> </ul> </div> </nav>`} />

Translucent menus

Blur and saturate the background of menus to create a translucent effect with .menu-translucent.

Menu button </button> <div class="menu menu-translucent"> <a class="menu-item active" href="#">Active menu item</a> <a class="menu-item" href="#">Menu item</a> <a class="menu-item" href="#">Menu item</a> <a class="menu-item" href="#">Menu item</a> <a class="menu-item" href="#">Menu item</a> <hr class="menu-divider"> <a class="menu-item theme-danger" href="#">Danger menu item</a> </div>`} />

Placement

Use data-bs-placement on the toggle element to control where the menu appears.

  • Physical placements: top, bottom, left, right — fixed directions regardless of text direction.
  • Logical placements: start, end — automatically flip based on RTL. In LTR mode, start becomes left and end becomes right. In RTL mode, they swap.

All placements support -start and -end alignment modifiers (e.g., bottom-start, end-end).

Responsive

Change placement at different breakpoints using responsive prefixes. The syntax is breakpoint:placement, where breakpoint is one of sm, md, lg, xl, or 2xl. Multiple breakpoints can be combined in a single attribute, space-separated.

For example, data-bs-placement="bottom-start md:bottom-end lg:end-start" will:

  • Show the menu at bottom-start on small screens (default)
  • Switch to bottom-end at the md breakpoint
  • Switch to right-start at the lg breakpoint

Bottom start → md:bottom-end </button> <div class="menu"> <a class="menu-item" href="#">Action</a> <a class="menu-item" href="#">Another action</a> </div>

<button class="btn-solid theme-secondary" type="button" data-bs-toggle="menu" data-bs-placement="bottom lg:right" aria-expanded="false"> Bottom → lg:right </button> <div class="menu"> <a class="menu-item" href="#">Action</a> <a class="menu-item" href="#">Another action</a> </div>

<button class="btn-solid theme-secondary" type="button" data-bs-toggle="menu" data-bs-placement="top-end md:right-start xl:bottom-start" aria-expanded="false"> Multi-breakpoint </button> <div class="menu"> <a class="menu-item" href="#">Action</a> <a class="menu-item" href="#">Another action</a> </div>`} />

Resize your browser window to see the placement change at different breakpoints.

You can use <a> or <button> elements as menu items.

We use utility classes to display menus in our docs examples, but they’re not required for your own use.

<button class="menu-item" type="button">Action</button> <button class="menu-item" type="button">Another action</button> <button class="menu-item" type="button">Something else here</button> </div>`} />

You can also create non-interactive menu items with .menu-text. Feel free to style further with custom CSS or text utilities.

<span class="menu-text">Menu item text</span> <a class="menu-item" href="#">Action</a> <a class="menu-item" href="#">Another action</a> <a class="menu-item" href="#">Something else here</a> </div>`} />

Active

Add .active to items in the menu to style them as the active selection. 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.

<a class="menu-item" href="#">Regular link</a> <a class="menu-item active" href="#" aria-current="true">Active link</a> <a class="menu-item" href="#">Another link</a> </div>`} />

Disabled

Add .disabled to items in the menu to style them as disabled.

<a class="menu-item" href="#">Regular link</a> <a class="menu-item disabled" aria-disabled="true">Disabled link</a> <a class="menu-item" href="#">Another link</a> </div>`} />

Variants

You can use the theme- prefix to apply a theme color to a menu item.

<a class="menu-item theme-primary" href="#">Primary link</a> <a class="menu-item theme-secondary" href="#">Secondary link</a> <a class="menu-item theme-success" href="#">Success link</a> <a class="menu-item theme-danger" href="#">Danger link</a> </div> <div class="menu show position-static"> <a class="menu-item active theme-primary" href="#">Primary link</a> <a class="menu-item active theme-secondary" href="#">Secondary link</a> <a class="menu-item active theme-success" href="#">Success link</a> <a class="menu-item active theme-danger" href="#">Danger link</a> </div>`} />

Icons

Add .menu-item-icon directly to an <svg> to add an icon slot to menu items.

<button class="menu-item" type="button"> <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="menu-item-icon fg-3" viewBox="0 0 16 16"> <path fill-rule="evenodd" d="M4 2a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2zm2-1a1 1 0 0 0-1 1v8a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1V2a1 1 0 0 0-1-1zM2 5a1 1 0 0 0-1 1v8a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1v-1h1v1a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h1v1z"/> </svg> Copy </button> <button class="menu-item" type="button"> <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="menu-item-icon fg-3" viewBox="0 0 16 16"> <path d="M3.5 3.5c-.614-.884-.074-1.962.858-2.5L8 7.226 11.642 1c.932.538 1.472 1.616.858 2.5L8.81 8.61l1.556 2.661a2.5 2.5 0 1 1-.794.637L8 9.73l-1.572 2.177a2.5 2.5 0 1 1-.794-.637L7.19 8.61zm2.5 10a1.5 1.5 0 1 0-3 0 1.5 1.5 0 0 0 3 0m7 0a1.5 1.5 0 1 0-3 0 1.5 1.5 0 0 0 3 0"/> </svg> Cut </button> <hr class="menu-divider"> <button class="menu-item theme-danger" type="button"> <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="menu-item-icon" viewBox="0 0 16 16"> <path d="M6.5 1h3a.5.5 0 0 1 .5.5v1H6v-1a.5.5 0 0 1 .5-.5M11 2.5v-1A1.5 1.5 0 0 0 9.5 0h-3A1.5 1.5 0 0 0 5 1.5v1H1.5a.5.5 0 0 0 0 1h.538l.853 10.66A2 2 0 0 0 4.885 16h6.23a2 2 0 0 0 1.994-1.84l.853-10.66h.538a.5.5 0 0 0 0-1zm1.958 1-.846 10.58a1 1 0 0 1-.997.92h-6.23a1 1 0 0 1-.997-.92L3.042 3.5zm-7.487 1a.5.5 0 0 1 .528.47l.5 8.5a.5.5 0 0 1-.998.06L5 5.03a.5.5 0 0 1 .47-.53Zm5.058 0a.5.5 0 0 1 .47.53l-.5 8.5a.5.5 0 1 1-.998-.06l.5-8.5a.5.5 0 0 1 .528-.47M8 4.5a.5.5 0 0 1 .5.5v8.5a.5.5 0 0 1-1 0V5a.5.5 0 0 1 .5-.5"/> </svg> Delete </button> </div>`} />

Descriptions

Use .menu-item-content for a flex column layout and .menu-item-description for secondary text below the main label.

<button class="menu-item" type="button"> <span class="menu-item-content"> Publish now <small class="menu-item-description">Make this page visible immediately</small> </span> </button> <button class="menu-item" type="button"> <span class="menu-item-content"> Schedule <small class="menu-item-description">Set a future publish date</small> </span> </button> </div>`} />

Selected

Add .selected to a .menu-item to indicate the current selection.

<Example code={`<button class="btn-solid theme-secondary" type="button" data-bs-toggle="menu" aria-expanded="false">Select status</button> <div class="menu"> <button class="menu-item selected" type="button"> <div class="menu-item-content"> Selected menu item <small class="menu-item-description">Currently visible to users</small> </div> <svg class="menu-item-check" xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" viewBox="0 0 16 16"><path d="m2 7 4 5 8-8"/></svg> </button> <button class="menu-item" type="button"> <div class="menu-item-content"> Default menu item <small class="menu-item-description">Not yet published</small> </div> <svg class="menu-item-check" xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" viewBox="0 0 16 16"><path d="m2 7 4 5 8-8"/></svg> </button> </div>

<button class="btn-solid theme-secondary" type="button" data-bs-toggle="menu" aria-expanded="false">Select status</button> <div class="menu"> <button class="menu-item" type="button"> Default menu item <svg class="menu-item-check" xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" viewBox="0 0 16 16"><path d="m2 7 4 5 8-8"/></svg> </button> <button class="menu-item selected" type="button"> Selected menu item <svg class="menu-item-check" xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" viewBox="0 0 16 16"><path d="m2 7 4 5 8-8"/></svg> </button> <button class="menu-item" type="button"> Default menu item <svg class="menu-item-check" xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" viewBox="0 0 16 16"><path d="m2 7 4 5 8-8"/></svg> </button> </div>`} />

Headers

Add a header to label sections of actions in any menu.

<a class="menu-item" href="#">Action</a> <a class="menu-item" href="#">Action</a> <h6 class="menu-header">Menu header</h6> <a class="menu-item" href="#">Another action</a> </div>`} />

Dividers

Separate groups of related menu items with a divider.

<a class="menu-item" href="#">Action</a> <a class="menu-item" href="#">Another action</a> <a class="menu-item" href="#">Something else here</a> <hr class="menu-divider"> <a class="menu-item" href="#">Separated link</a> </div>`} />

Text

Place any freeform text within a menu with text and use margin and padding utilities. Note that you’ll likely need additional sizing styles to constrain the menu width.

<Example code={&lt;div class="menu show position-static p-3 fg-2" style="--bs-menu-min-width: 240px;"> &lt;p> Some example text that’s free-flowing within the menu. &lt;/p> &lt;p class="mb-0"> And this is more example text. &lt;/p> &lt;/div>} />

Forms

Put a form within a menu, or make it into a menu, and use margin and padding utilities to give it the negative space you require.

<Example code={&lt;div class="menu show position-static" style="--bs-menu-min-width: 300px;"> &lt;form class="d-flex flex-column gap-3 p-3"> &lt;div> &lt;label for="exampleMenuFormEmail1" class="form-label">Email address&lt;/label> &lt;input type="email" class="form-control" id="exampleMenuFormEmail1" placeholder="email@example.com"> &lt;/div> &lt;div> &lt;label for="exampleMenuFormPassword1" class="form-label">Password&lt;/label> &lt;input type="password" class="form-control" id="exampleMenuFormPassword1" placeholder="Password"> &lt;/div> &lt;div class="form-field"> &lt;input type="checkbox" id="checkLabel" class="check" /> &lt;label for="checkLabel">Example new checkbox&lt;/label> &lt;/div> &lt;div class="vstack gap-2"> &lt;button type="submit" class="btn-solid theme-primary">Sign in&lt;/button> &lt;a class="theme-secondary" href="#">New around here? Sign up&lt;/a> &lt;a class="theme-secondary" href="#">Forgot password?&lt;/a> &lt;/div> &lt;/form> &lt;/div>} />

Scrollable menus

Assign --bs-menu-max-height and --bs-menu-overflow-y custom properties to constrain the menu height and enable scrolling.

<button class="menu-item" type="button">Item 1</button> <button class="menu-item" type="button">Item 2</button> <button class="menu-item" type="button">Item 3</button> <button class="menu-item" type="button">Item 4</button> <button class="menu-item" type="button">Item 5</button> <button class="menu-item" type="button">Item 6</button> <button class="menu-item" type="button">Item 7</button> <button class="menu-item" type="button">Item 8</button> </div>`} />