Drawer
Source: https://getbootstrap.com/docs/6.0/components/drawer
Build hidden sidebars or drawers into your project for navigation, shopping carts, and more with a few classes and our JavaScript plugin. Replaces the old Offcanvas component.
How it works
Drawer builds on the native <dialog> element and our Dialog component to manage hidden sidebars via JavaScript. These sidebars, or drawers, can appear from the left, right, top, or bottom edge of the viewport. Buttons or anchors are used as triggers that are attached to specific elements you toggle, and data attributes are used to invoke our JavaScript.
- Drawer shares the same base as our Dialog component, using native
<dialog>APIs for focus trapping, backdrop, and top-layer rendering. - Use the
<dialog>element, not a<div>. Due to how CSS handles animations, don’t applymarginortranslatedirectly to.drawer— wrap it if you need those. - Modal by default — opens with
showModal(), a backdrop, and focus trapping. Setscroll: trueandbackdrop: falseto open as a non-modal drawer withshow(): body scrolling stays on, and focus is not trapped. - Built-in backdrop via
::backdrop(modal only) closes the drawer on click; setbackdrop: "static"to lock clicks outside, orbackdrop: falseto hide it. - Escape key handling closes the drawer by default; set
keyboard: falseto disable. - Swipe to dismiss — drawer auto-wires a placement-aware swipe (swipe left to close
drawer-startin LTR, swipe down to closedrawer-bottom, etc.). - Responsive placement —
.sm:drawer,.md:drawer, and up stay drawer-like below their breakpoint and collapse inline above it, making drawers useful as responsive navbars. - Only one drawer can be shown at a time (enforced by the data API).
- Animated open and close — drawer slides back out to its placement-specific off-screen position on close, with the
::backdropfading alongside it when opened modally. When authoring custom CSS, qualify your[open]rules with:not(.hiding)so the exit transition can fall through to the base state; add.drawer-instantto skip animations.
Examples
Drawer components
Below is a drawer example that is shown by default (via open and .show on the <dialog>). Drawer includes support for a header with a close button and an optional body class for some initial padding. We suggest that you include drawer headers with dismiss actions whenever possible, or provide an explicit dismiss action.
<div class="drawer-header"> <h5 class="drawer-title" id="drawerLabel">Drawer</h5> </div> <div class="drawer-body"> Content for the drawer goes here. You can place just about any Bootstrap component or custom elements here. </div> </dialog>`} />
Live demo
Use the buttons below to show and hide a drawer element via JavaScript. You can use a link with the href attribute, or a button with the data-bs-target attribute. In both cases, the data-bs-toggle="drawer" is required.
Link with href </a> <button class="btn-solid theme-primary" type="button" data-bs-toggle="drawer" data-bs-target="#drawerExample" aria-controls="drawerExample"> Button with data-bs-target </button>
<dialog class="drawer drawer-start" tabindex="-1" id="drawerExample" aria-labelledby="drawerExampleLabel"> <div class="drawer-header"> <h5 class="drawer-title" id="drawerExampleLabel">Drawer</h5> </div> <div class="drawer-body"> <div> Some text as placeholder. In real life you can have the elements you have chosen. Like, text, images, lists, etc. </div> <div class="mt-3"> <button class="btn-solid theme-secondary" type="button" data-bs-toggle="menu"> 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> </div> </div> </dialog>`} />
Without JavaScript
Supported browsers can open and close a drawer with the Invoker Commands API—no Bootstrap JavaScript required. Set commandfor to the drawer’s id, use command="show-modal" to open, and command="close" to dismiss.
The Invoker Commands API is not supported in all browsers. For guaranteed support, use the data-bs-toggle examples above when you need our plugin options, events, swipe to dismiss, or animated close.
Open drawer </button>
<dialog class="drawer drawer-start" tabindex="-1" id="invokerDrawer" aria-labelledby="invokerDrawerLabel"> <div class="drawer-header"> <h5 class="drawer-title" id="invokerDrawerLabel">Invoker Commands</h5> <button type="button" class="btn-close" commandfor="invokerDrawer" command="close" aria-label="Close"></button> </div> <div class="drawer-body"> <p>This drawer opens with <code>command="show-modal"</code> and closes with <code>command="close"</code>. No Bootstrap JavaScript is involved.</p> </div> </dialog>`} />
Body scrolling
Scrolling the <body> element is disabled when a drawer opens modally. Use data-bs-scroll="true" with data-bs-backdrop="false" to keep body scrolling and open the drawer as non-modal. Focus moves into the drawer, but is not trapped, so the page stays interactive.
<Example code={`<button class="btn-solid theme-primary" type="button" data-bs-toggle="drawer" data-bs-target="#drawerScrolling" aria-controls="drawerScrolling">Enable body scrolling</button>
<dialog class="drawer drawer-start" data-bs-scroll="true" data-bs-backdrop="false" tabindex="-1" id="drawerScrolling" aria-labelledby="drawerScrollingLabel"> <div class="drawer-header"> <h5 class="drawer-title" id="drawerScrollingLabel">Drawer with body scrolling</h5> </div> <div class="drawer-body"> <p>Try scrolling the rest of the page to see this option in action.</p> </div> </dialog>`} />
Body scrolling & backdrop
You can also allow <body> scrolling while keeping a backdrop. With a backdrop present, the drawer stays modal (showModal() and focus trapping) even when scroll is true.
<Example code={`<button class="btn-solid theme-primary" type="button" data-bs-toggle="drawer" data-bs-target="#drawerWithBothOptions" aria-controls="drawerWithBothOptions">Enable both scrolling & backdrop</button>
<dialog class="drawer drawer-start" data-bs-scroll="true" tabindex="-1" id="drawerWithBothOptions" aria-labelledby="drawerWithBothOptionsLabel"> <div class="drawer-header"> <h5 class="drawer-title" id="drawerWithBothOptionsLabel">Backdrop with scrolling</h5> </div> <div class="drawer-body"> <p>Try scrolling the rest of the page to see this option in action.</p> </div> </dialog>`} />
Static backdrop
When backdrop is set to static, the drawer will not close when clicking outside of it.
Toggle static drawer </button>
<dialog class="drawer drawer-start" data-bs-backdrop="static" tabindex="-1" id="staticBackdrop" aria-labelledby="staticBackdropLabel"> <div class="drawer-header"> <h5 class="drawer-title" id="staticBackdropLabel">Drawer</h5> </div> <div class="drawer-body"> <div> I will not close if you click outside of me. </div> </div> </dialog>`} />
Instant drawer
By default, drawers animate with a slide on open and close. To disable animations, add .drawer-instant to the <dialog> element.
Toggle instant drawer </button>
<dialog class="drawer drawer-start drawer-instant" tabindex="-1" id="instantDrawer" aria-labelledby="instantDrawerLabel"> <div class="drawer-header"> <h5 class="drawer-title" id="instantDrawerLabel">Instant drawer</h5> </div> <div class="drawer-body"> <p>This drawer doesn’t animate and appears instantly on open and close.</p> </div> </dialog>`} />
Dark drawer
Change the appearance of drawers with utilities to better match them to different contexts like dark navbars. Here we add data-bs-theme="dark" to the .drawer, and it makes all nested elements within use dark mode.
<div class="drawer-header"> <h5 class="drawer-title" id="drawerDarkLabel">Drawer</h5> </div> <div class="drawer-body"> <p>Place drawer content here.</p> </div> </dialog>`} />
Translucent drawer
Add .drawer-translucent to the drawer panel to blur and saturate the background. This makes the panel semi-transparent so content behind it shows through.
Toggle translucent drawer </button>
<dialog class="drawer drawer-start drawer-translucent" tabindex="-1" id="drawerTranslucent" aria-labelledby="drawerTranslucentLabel"> <div class="drawer-header"> <h5 class="drawer-title" id="drawerTranslucentLabel">Translucent drawer</h5> </div> <div class="drawer-body"> Content for the translucent drawer goes here. The background blurs and saturates whatever is behind it. </div> </dialog>`} />
Sheet
Add .drawer-sheet to render the panel flush against the viewport edge. The sheet variant removes the drawer’s inset, border, border-radius, and box-shadow, so it sits edge-to-edge like a traditional offcanvas. It works with any placement.
Toggle sheet drawer </button>
<dialog class="drawer drawer-bottom drawer-sheet" tabindex="-1" id="drawerSheet" aria-labelledby="drawerSheetLabel"> <div class="drawer-header"> <h5 class="drawer-title" id="drawerSheetLabel">Sheet drawer</h5> </div> <div class="drawer-body"> Content for the sheet drawer goes here. It sits flush to the edge with no inset, border, rounded corners, or shadow. </div> </dialog>`} />
