Drawer
A panel that slides in from an edge of the screen and slides back out: a site menu, a cart, filters, details. It is a dialog underneath, so focus stays inside, Esc closes it and the page behind can't scroll. A tap outside closes it too.
Drawer
Open it with data-momo-dialog="id" on a button. .dialog-drawer comes in from the right; .dialog-drawer-start from the left (both flip in right-to-left pages).
<button class="btn" type="button" data-momo-dialog="dr-cart"><i class="mi mi-shopping-bag" aria-hidden="true"></i> Cart (2)</button>
<dialog class="dialog dialog-drawer" id="dr-cart" aria-labelledby="dr-cart-title">
<div class="dialog-header">
<h2 class="dialog-title" id="dr-cart-title">Your cart</h2>
<button class="btn btn-icon btn-sm btn-ghost" type="button" data-momo-close aria-label="Close"><i class="mi mi-x" aria-hidden="true"></i></button>
</div>
<div class="dialog-body stack">
<div class="hstack">
<div class="box p-0 w-16 h-16 bg-yellow-soft shrink-0" aria-hidden="true"></div>
<div class="grow"><b>Desk lamp</b><div class="text-sm text-muted">Yellow · 1 × $48</div></div>
<button class="btn btn-icon btn-sm btn-ghost" type="button" aria-label="Remove desk lamp"><i class="mi mi-trash" aria-hidden="true"></i></button>
</div>
<div class="hstack">
<div class="box p-0 w-16 h-16 bg-violet-soft shrink-0" aria-hidden="true"></div>
<div class="grow"><b>Notebook</b><div class="text-sm text-muted">Dotted · 2 × $12</div></div>
<button class="btn btn-icon btn-sm btn-ghost" type="button" aria-label="Remove notebook"><i class="mi mi-trash" aria-hidden="true"></i></button>
</div>
</div>
<div class="dialog-footer">
<span class="me-auto"><span class="text-muted">Total</span> <b>$72</b></span>
<button class="btn btn-brand" type="button" data-momo-close>Check out</button>
</div>
</dialog>Site menu
For a website's menu on phones, put a .drawer-nav list in the drawer: big links with icons, groups that open in place. Picking a link closes the drawer.
<button class="btn btn-icon" type="button" data-momo-dialog="dr-menu" aria-label="Menu"><i class="mi mi-menu" aria-hidden="true"></i></button>
<dialog class="dialog dialog-drawer dialog-drawer-start dialog-sm" id="dr-menu" aria-label="Menu">
<div class="dialog-header">
<a class="navbar-brand" href="#"><span class="navbar-mark"><i class="mi mi-letter-m mi-stroke-2.5" aria-hidden="true"></i></span>Momo</a>
<button class="btn btn-icon btn-sm btn-ghost" type="button" data-momo-close aria-label="Close"><i class="mi mi-x" aria-hidden="true"></i></button>
</div>
<nav class="dialog-body" aria-label="Site">
<ul class="drawer-nav">
<li><a href="#" aria-current="page"><i class="mi mi-home" aria-hidden="true"></i>Home</a></li>
<li>
<details>
<summary><i class="mi mi-box" aria-hidden="true"></i>Product<i class="mi mi-chevron-down drawer-nav-caret" aria-hidden="true"></i></summary>
<ul><li><a href="#">Dashboards</a></li><li><a href="#">Boards</a></li><li><a href="#">Calendar</a></li></ul>
</details>
</li>
<li><a href="#"><i class="mi mi-tag" aria-hidden="true"></i>Pricing</a></li>
<li><a href="#"><i class="mi mi-book-open" aria-hidden="true"></i>Docs</a></li>
<li><a href="#"><i class="mi mi-life-buoy" aria-hidden="true"></i>Help</a></li>
</ul>
</nav>
<div class="dialog-footer">
<a class="btn grow" href="#">Sign in</a>
<a class="btn btn-brand grow" href="#">Get started</a>
</div>
</dialog>The navbar already folds into its own side panel; use a drawer when you build the menu button yourself, or for anything that isn't the main menu.
Top and bottom
.dialog-drawer-bottom is a sheet that comes up from the bottom (with a small grab bar), .dialog-drawer-top drops down from the top. Both are full width and as tall as their content, up to 85% of the screen.
<button class="btn" type="button" data-momo-dialog="dr-share"><i class="mi mi-share" aria-hidden="true"></i> Share</button>
<dialog class="dialog dialog-drawer dialog-drawer-bottom" id="dr-share" aria-labelledby="dr-share-title">
<div class="dialog-header">
<h2 class="dialog-title" id="dr-share-title">Share this page</h2>
<button class="btn btn-icon btn-sm btn-ghost" type="button" data-momo-close aria-label="Close"><i class="mi mi-x" aria-hidden="true"></i></button>
</div>
<div class="dialog-body">
<div class="cluster">
<button class="btn" type="button" data-momo-close><i class="mi mi-link" aria-hidden="true"></i> Copy link</button>
<button class="btn" type="button" data-momo-close><i class="mi mi-mail" aria-hidden="true"></i> Email</button>
<button class="btn" type="button" data-momo-close><i class="mi mi-bluesky" aria-hidden="true"></i> Bluesky</button>
</div>
</div>
</dialog>
<button class="btn" type="button" data-momo-dialog="dr-search"><i class="mi mi-search" aria-hidden="true"></i> Search</button>
<dialog class="dialog dialog-drawer dialog-drawer-top" id="dr-search" aria-label="Search">
<div class="dialog-body">
<div class="container container-md">
<label class="visually-hidden" for="dr-search-q">Search the site</label>
<input class="form-control form-control-lg" id="dr-search-q" type="search" placeholder="Search the site…" autofocus>
<p class="text-sm text-muted mt-3 mb-0">Try "pricing" or "dark mode". <kbd>Esc</kbd> closes.</p>
</div>
</div>
</dialog>Floating
.dialog-drawer-float keeps a gap around the drawer and gives it rounded corners and a shadow. It works on every side.
<button class="btn" type="button" data-momo-dialog="dr-float"><i class="mi mi-bell" aria-hidden="true"></i> Notifications</button>
<dialog class="dialog dialog-drawer dialog-drawer-float dialog-sm" id="dr-float" aria-labelledby="dr-float-title">
<div class="dialog-header">
<h2 class="dialog-title" id="dr-float-title">Notifications</h2>
<button class="btn btn-icon btn-sm btn-ghost" type="button" data-momo-close aria-label="Close"><i class="mi mi-x" aria-hidden="true"></i></button>
</div>
<div class="dialog-body stack">
<p class="m-0"><b>Ana</b> commented on <b>Homepage</b><br><span class="text-sm text-muted">2 minutes ago</span></p>
<p class="m-0"><b>Leo</b> moved <b>Pricing page</b> to Done<br><span class="text-sm text-muted">1 hour ago</span></p>
<p class="m-0">Your export is ready<br><span class="text-sm text-muted">Yesterday</span></p>
</div>
</dialog>
<button class="btn" type="button" data-momo-dialog="dr-float-b">Bottom, floating</button>
<dialog class="dialog dialog-drawer dialog-drawer-bottom dialog-drawer-float" id="dr-float-b" aria-label="Cookie settings">
<div class="dialog-body hstack flex-wrap">
<p class="m-0 grow">We use one cookie to remember your theme. That's it.</p>
<button class="btn btn-brand" type="button" data-momo-close>OK</button>
</div>
</dialog>Shadow
Drawers and side menus are flat by default, on every screen size: the line along their edge is enough. Add .drawer-shadow to one drawer to give it a hard shadow, or turn shadows on for the whole page with class="momo-shadows" on <html>. It works on dialog drawers, the phone navbar menu, the site sidebar and the app sidebar.
Every drawer dims the page behind it while open: the backdrop fades in with the drawer and out with it, and a tap on it closes the drawer. --momo-backdrop sets its color.
<button class="btn" type="button" data-momo-dialog="dr-shadow">With a shadow</button>
<dialog class="dialog dialog-drawer dialog-drawer-start dialog-sm drawer-shadow" id="dr-shadow" aria-labelledby="dr-shadow-title">
<div class="dialog-header">
<h2 class="dialog-title" id="dr-shadow-title">Menu</h2>
<button class="btn btn-icon btn-sm btn-ghost" type="button" data-momo-close aria-label="Close"><i class="mi mi-x" aria-hidden="true"></i></button>
</div>
<div class="dialog-body"><p class="m-0">This drawer asked for a shadow with <code>.drawer-shadow</code>.</p></div>
</dialog>Classes
| Class | Does |
|---|---|
.dialog.dialog-drawer | A side panel from the right, 384px wide, full height |
.dialog-drawer-start | From the left |
.dialog-drawer-top / -bottom | Full width, from the top / a bottom sheet with a grab bar |
.dialog-drawer-float | A gap around it, rounded, with a shadow (--drawer-gap, 12px) |
.dialog-sm / .dialog-lg / .dialog-full | 320px / 576px / the whole width |
.drawer-nav | A site menu: big links, <details> groups, aria-current for the current page |
data-momo-close-outside="false" | Keep it open on a tap outside (for a form that shouldn't be lost) |
The header, body and footer are the dialog's: .dialog-header, .dialog-body (scrolls), .dialog-footer. Open and close from script with Momo.dialog.open('id') and Momo.dialog.close('id').
Accessibility
- Give the drawer a name:
aria-labelledbypointing at its title, oraria-label. - The button that opens it gets
aria-expanded, and focus goes back to it when the drawer closes. - With reduced motion turned on, drawers appear and disappear without sliding.