Skip to content

Pure CSS Off-Canvas Drawer

Off-canvas side drawer toggled with the CSS checkbox hack: slide-in navigation, scrim, animated burger icon and no JavaScript.

Also known as: off canvas sidebar menu, slide in side menu, checkbox hack drawer, side navigation panel

Pure CSS Off-Canvas Drawer live demo

Open in new tab

Pure CSS code (HTML, CSS)

An off-canvas side drawer built with pure CSS and the checkbox hack, without a single line of JavaScript. A Menu button in the top bar slides in a navigation panel with icons, count badges, a team list and a user card, while a dimmed scrim covers the page. Use it as the mobile navigation of an app, a dashboard sidebar or a filter panel on sites where you want to avoid scripts.

How it works

The root .od-shell is positioned relatively and clips its children. Its first child is the input.od-toggle checkbox, which stores the open state. Three label elements point to it with for="od-toggle-1": .od-burger in the .od-bar header, .od-close inside the drawer and the full-size .od-scrim. Clicking any of them toggles the checkbox.

All the behavior comes from the general sibling selector. .od-toggle:checked ~ .od-drawer slides the nav.od-drawer from translateX(-100%) to 0, .od-toggle:checked ~ .od-scrim fades in the overlay, and .od-toggle:checked ~ .od-bar .od-burger-lines morphs the three burger lines into an X. While the drawer is closed it also has visibility: hidden; the visibility change is delayed until the slide-out transition finishes, so the panel animates out smoothly and its links leave the tab order. Inside the drawer, .od-link items use aria-current="page" for the active entry, .od-badge shows counts and .od-user sticks to the bottom with margin-top: auto.

Customization

  • checked on .od-toggle: the demo starts with the drawer open; remove the attribute to start closed.
  • --od-width on .od-shell: drawer width, e.g. 360px for a wider panel (it never exceeds 86% of the shell).
  • --od-speed: duration of the slide, fade and burger animation, e.g. 0.2s for a snappier drawer.
  • --od-accent and --od-accent-soft: the violet used for the active link, badges, the Menu button and focus rings.
  • --od-scrim: color and opacity of the overlay, e.g. rgba(0, 0, 0, 0.6) for a darker backdrop.
  • --od-height: minimum height of the demo shell; set it to 100vh for a full-page app layout.
  • To open from the right, change left: 0 to right: 0 on .od-drawer and translateX(-100%) to translateX(100%).

Use cases

  • Mobile app navigation: a Menu button slides in a panel with icons and count badges, no scripts needed
  • Admin dashboards: the drawer works as a sidebar with a team list and a user card pinned at the bottom
  • Filter panels on shops: a slide-in panel with a dimmed scrim keeps the product page clean until needed
  • Script-free sites: pages that must avoid JavaScript still get an animated burger icon and smooth slide-out

Accessibility

The checkbox is visually hidden but stays in the tab order, so keyboard users reach it with Tab and toggle it with Space. Its label "Menu" gives it an accessible name, aria-controls points to the drawer, and a 3px outline appears around .od-burger when the checkbox has :focus-visible. The drawer is a nav with aria-label, the team list is labelled by its heading, and the decorative scrim and icons are aria-hidden. Because a closed drawer is visibility: hidden, screen readers and the Tab key skip its links. Under prefers-reduced-motion the drawer, scrim and burger switch instantly.

Usage notes

A CSS-only drawer cannot close on the Escape key or move focus automatically; add a small script if you need those. For a full-page layout, switch .od-drawer and .od-scrim from position: absolute to position: fixed. Give each extra instance its own checkbox id.

Pure CSS Off-Canvas Drawer at a glance

Framework
Pure CSS
Code
HTML, CSS
JavaScript
Not needed, CSS only
Dependencies
None
Layout
Responsive, works on mobile
Category
Drawers
License
Free for personal and commercial use

Questions about this template

Can I use the Pure CSS Off-Canvas Drawer code for free?

Yes. You can copy or download the code and use it in personal and commercial projects, including client work. No sign-up is needed. Reselling it as part of a component library or template collection is not allowed; see the license.

How do I add it to my website?

There is nothing to install. Paste the HTML where the component should appear and add the CSS to your stylesheet. Download HTML gives you a complete page with everything already linked.

Does it need jQuery or a JavaScript framework?

No. It is built with HTML and CSS only, so there is no JavaScript to load.

Does it work on mobile?

Yes. The layout adapts to small screens. Use the Mobile and Tablet buttons above the live demo to check it at phone and tablet width.

Requirements

No dependencies. Pure HTML, CSS and JavaScript.

Pure CSS Off-Canvas Drawer – free Pure CSS drawer template
Pure CSS Off-Canvas Drawer · free Pure CSS drawer template

More Drawers

Settings Drawer with Tabs – free Bootstrap 6 drawer template

Settings Drawer with Tabs

Dark Bootstrap 6 Drawer with tabbed settings panels (General, Alerts, Privacy), switches, a Range slider, select menus and a save bar that tracks unsaved changes.

Bottom Drawer Action Sheet – free Bootstrap 6 drawer template

Bottom Drawer Action Sheet

Bootstrap 6 bottom Drawer styled as a mobile action sheet with a share row, edit actions in a list group, pin toggle, delete action and confirmation toasts.

Filter Drawer for Product Lists – free Bootstrap 6 drawer template

Filter Drawer for Product Lists

Bootstrap 6 Drawer from the left with category checks, a Range price slider, feature toggles, rating, in-stock switch, live result count and apply/reset buttons.

Drawer Shopping Cart – free Bootstrap 6 drawer template

Drawer Shopping Cart

Bootstrap 6 Drawer shopping cart that slides in from the right with product rows, quantity steppers, a free-shipping progress bar, subtotal and checkout.

Notification Drawer Panel – free Bootstrap 5 drawer template

Notification Drawer Panel

Bootstrap 5 offcanvas notification drawer with notifications grouped by day, unread filter, mark all as read and dismiss buttons.

Offcanvas Shopping Cart – free Bootstrap 5 drawer template

Offcanvas Shopping Cart

Bootstrap 5 offcanvas cart drawer with quantity steppers, remove buttons, free-shipping progress, live totals and an empty state.