# Nested Sidebar Menu

> A docs-style sidebar with collapsible groups built on details and summary, plus a guide line for children.

- Category: [CSS Navigation](https://copy-css.com/category/navigation)
- Tags: sidebar, tree, details, submenu, docs, collapsible
- Live preview: https://copy-css.com/snippets/nested-sidebar-menu
- License: Free for personal and commercial use. No signup, no attribution required.

## HTML

```html
<nav class="tree-nav" aria-label="Docs">
  <a href="#">Introduction</a>
  <details open>
    <summary>Components</summary>
    <a href="#">Buttons</a>
    <a href="#" aria-current="page">Cards</a>
    <a href="#">Forms</a>
  </details>
  <details>
    <summary>Guides</summary>
    <a href="#">Theming</a>
    <a href="#">Dark mode</a>
  </details>
</nav>
```

## CSS

```css
.tree-nav {
  display: grid;
  gap: 2px;
  width: 200px;
  color: #334155;
  font: 500 14px/1.4 system-ui, sans-serif;
}

.tree-nav a,
.tree-nav summary {
  display: block;
  padding: 7px 10px;
  border-radius: 8px;
  color: inherit;
  text-decoration: none;
  cursor: pointer;
}

.tree-nav summary {
  position: relative;
  color: #0f172a;
  font-weight: 600;
  list-style: none;
}

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

/* Chevron */
.tree-nav summary::after {
  content: "";
  position: absolute;
  top: 50%;
  right: 12px;
  width: 6px;
  height: 6px;
  margin-top: -5px;
  border: solid #94a3b8;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
  transition: transform 0.2s ease;
}

.tree-nav details[open] > summary::after {
  margin-top: -2px;
  transform: rotate(-135deg);
}

.tree-nav details > a {
  margin-left: 14px;
  padding-left: 14px;
  border-left: 1px solid #e2e8f0;
  border-radius: 0 8px 8px 0;
  color: #64748b;
}

.tree-nav a:hover,
.tree-nav summary:hover {
  background: #f1f5f9;
}

.tree-nav a[aria-current="page"] {
  border-left-color: #2563eb;
  background: #eff6ff;
  color: #1d4ed8;
}

.tree-nav a:focus-visible,
.tree-nav summary:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: -2px;
}
```

## Notes

- This CSS Nested Sidebar Menu is 73 lines of pure CSS (1.2 KB) with no JavaScript and no dependencies. It uses transitions, transforms, CSS Grid and keyboard focus styles.
- In JSX use `className` instead of `class`. In Tailwind projects put the CSS in the global stylesheet.
