Slide Drawer

Right side slide-over drawer with header, nav links, and a close button.

Tailwind CSS
<div class="relative w-full h-72 rounded-xl bg-slate-100 overflow-hidden">
  <div class="absolute inset-0 bg-slate-900/40"></div>
  <aside class="absolute top-0 right-0 bottom-0 w-60 max-w-[75%] bg-white shadow-xl p-5 flex flex-col">
    <div class="flex items-center justify-between mb-6">
      <span class="font-semibold text-slate-900">Menu</span>
      <button aria-label="Close menu" class="w-8 h-8 rounded-full hover:bg-slate-100 flex items-center justify-center text-slate-500">
        <svg class="w-4 h-4" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12"/></svg>
      </button>
    </div>
    <nav class="flex flex-col gap-1">
      <a href="#" class="px-3 py-2 rounded-lg text-sm font-medium text-slate-900 bg-slate-100">Home</a>
      <a href="#" class="px-3 py-2 rounded-lg text-sm text-slate-600 hover:bg-slate-100">Features</a>
      <a href="#" class="px-3 py-2 rounded-lg text-sm text-slate-600 hover:bg-slate-100">Pricing</a>
      <a href="#" class="px-3 py-2 rounded-lg text-sm text-slate-600 hover:bg-slate-100">Contact</a>
    </nav>
  </aside>
</div>

Free to use in personal and commercial projects. No attribution required.

Variants

Same component, different looks. Preview each one live and copy the code you like.

Left drawer

A left drawer matches apps where navigation has always lived on the left.

Tailwind CSS

Settings panel

The settings panel variant keeps quick toggles one tap away without leaving the screen.

Tailwind CSS

Mini cart

The mini cart drawer is the standard pattern for e-commerce quick checkout.

Tailwind CSS

About this slide drawer

A slide-over drawer slides in from the edge to reveal navigation, filters, or settings without leaving the page. It is the standard mobile navigation pattern and a handy secondary panel on desktop layouts.

This demo shows the open state statically. A backdrop with bg-slate-900/40 dims the page, while an absolutely positioned aside pinned to the right holds the header, close button, and nav links. The panel uses max-w-[75%] so it never covers the full screen on phones.

In production, toggle the drawer with a class that translates the panel off-canvas, like translate-x-full, paired with transition-transform. Always combine the drawer with the backdrop and a real close button, and trap focus inside while it is open for keyboard users.

Mobile screens have no room for persistent navigation, yet users still need menus, filters, and settings. The slide-over drawer solves it by borrowing the edge of the screen temporarily: it glides in, does its job, and leaves without a page change. It is the standard mobile navigation pattern because it preserves context better than any full-page alternative.

This demo shows the open state statically. A backdrop with bg-slate-900/40 dims the page and signals modality, while an absolutely positioned aside pinned to the right holds the header, close button, and nav links. The panel caps at max-w-[75%] so it never swallows the whole phone screen. In production, the closed state is translate-x-full with a transform transition, toggled by your framework.

Trap focus inside the drawer while it is open: tab should cycle through drawer controls, never escape to the page behind. Return focus to the trigger button on close, or keyboard users lose their place. Lock body scroll while the drawer is open; a scrolling background behind a fixed drawer feels broken on mobile. Size the drawer at 320 to 400px; wider drawers on desktop start competing with the page instead of assisting it.

Forgetting to lock body scroll is the disorienting failure. The drawer opens, the user swipes, and the page behind it scrolls instead, so the backdrop drifts and the whole interface feels broken. Set overflow-hidden on the body while the drawer is open and restore it on close. The background must freeze the moment the drawer takes over.

Where to use it

  • ✓ Mobile navigation menus
  • ✓ Filter panels on listing pages
  • ✓ Settings side panels
  • ✓ Cart drawers on ecommerce sites

Customization tips

Flip the drawer to the left edge by swapping right-0 for left-0, or widen it with w-72 on desktop. For the closed state, add translate-x-full with transition-transform and toggle it from your framework.

Design notes

When to use

Slide drawers fit secondary content that should not take over the page: mobile navigation, filter panels, shopping cart summaries, and settings sheets. Sliding in from the edge keeps the visitor's context visible behind it, which is why it beats a full page reload for these jobs. On mobile it is the standard navigation pattern users already expect.

What to avoid

Do not put critical flows like checkout inside a drawer, because the cramped width and easy dismissal invite abandonment. Avoid stacking a modal on top of a drawer, since layered dismissals confuse everyone. And do not make the drawer so wide on phones that it leaves no visible backdrop, or users lose the sense that they can go back.

Accessibility

Trap focus inside the drawer while it is open, close it on Escape, and return focus to the trigger button when it closes. Give it a dialog role with an accessible name, and make the backdrop click dismiss it for pointer users.

Frequently asked questions

How do I animate the drawer sliding in and out?

Give the aside transition-transform and toggle between translate-x-full for hidden and translate-x-0 for open. Fade the backdrop opacity on the same toggle for a polished feel.

Should the page behind the drawer scroll?

No. Lock body scroll while the drawer is open, usually by toggling overflow-hidden on the body element, and restore it when the drawer closes.

How wide should a drawer be?

Around 320px, which is w-80, works well for navigation and filters. Keep it under 75 percent of the viewport on phones so it reads as an overlay rather than a new page.

How do I close the drawer with the Escape key?

Add a keydown listener that checks for the Escape key and closes the drawer, but only attach it while the drawer is open and remove it on close. Return focus to the button that opened the drawer so keyboard users do not lose their place. This is expected behavior users will try before hunting for the close button.

Should the drawer have a backdrop overlay?

Yes for modal drawers that demand attention, like settings panels or checkout sidebars: a dimmed backdrop signals the page behind is paused and gives users a big click target to dismiss. Skip the backdrop for non-modal drawers like a persistent docs nav, where users need to interact with the page and the drawer at the same time.

How do I trap focus inside an open drawer?

On open, move focus to the first focusable element in the drawer, then intercept Tab and Shift+Tab at the first and last elements to cycle within. Without a trap, keyboard users can tab into the invisible page behind the drawer. Keep the implementation small: a keydown handler on the drawer container is enough for most cases.