# Off-canvas Menu

> A slide-in drawer menu with no JavaScript, built on <details> so it is keyboard and screen reader friendly.

- Category: [CSS Navigation](https://copy-css.com/category/navigation)
- Tags: drawer, sidebar, off-canvas, details, mobile menu, slide
- Live preview: https://copy-css.com/snippets/offcanvas-menu
- License: Free for personal and commercial use. No signup, no attribution required.

## HTML

```html
<details class="offcanvas">
  <summary aria-label="Menu"></summary>
  <nav>
    <a href="#">Home</a>
    <a href="#">Projects</a>
    <a href="#">About</a>
    <a href="#">Contact</a>
  </nav>
</details>
```

## CSS

```css
.offcanvas summary {
  position: relative;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: #0f172a;
  color: #fff;
  list-style: none;
  cursor: pointer;
}

.offcanvas summary::-webkit-details-marker {
  display: none;
}

/* Hamburger: three lines that fold into an X when open */
.offcanvas summary::before,
.offcanvas summary::after {
  content: "";
  grid-area: 1 / 1;
  width: 18px;
  height: 2px;
  border-radius: 2px;
  background: currentColor;
  transition: transform 0.25s ease, box-shadow 0.25s ease;
}

.offcanvas summary::before {
  box-shadow: 0 -6px currentColor, 0 6px currentColor;
}

.offcanvas[open] summary::before {
  box-shadow: 0 0 transparent, 0 0 transparent;
  transform: rotate(45deg);
}

.offcanvas[open] summary::after {
  transform: rotate(-45deg);
}

.offcanvas summary:focus-visible {
  outline: 2px solid #38bdf8;
  outline-offset: 2px;
}

.offcanvas nav {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 1;
  display: grid;
  align-content: start;
  gap: 4px;
  width: min(260px, 80vw);
  padding: 72px 12px 12px;
  background: #fff;
  box-shadow: 8px 0 32px -12px rgba(0, 0, 0, 0.35);
  animation: offcanvas-in 0.3s cubic-bezier(0.3, 0.7, 0.4, 1);
}

.offcanvas nav a {
  padding: 10px 12px;
  border-radius: 8px;
  color: #334155;
  font: 500 15px system-ui, sans-serif;
  text-decoration: none;
}

.offcanvas nav a:hover {
  background: #f1f5f9;
  color: #0f172a;
}

@keyframes offcanvas-in {
  from { transform: translateX(-100%); }
}

@media (prefers-reduced-motion: reduce) {
  .offcanvas nav {
    animation: none;
  }
}
```

## Notes

- This CSS Off-canvas Menu is 84 lines of pure CSS (1.6 KB) with no JavaScript and no dependencies. It uses keyframe animations, transitions, transforms and box shadows.
- In JSX use `className` instead of `class`. In Tailwind projects put the CSS in the global stylesheet.
