# Expanding Icon Sidebar

> A slim icon-only sidebar rail that widens to show labels on hover or keyboard focus.

- Category: [CSS Navigation](https://copy-css.com/category/navigation)
- Tags: sidebar, icon rail, collapsible, hover, focus-within, dashboard
- Live preview: https://copy-css.com/snippets/icon-rail-sidebar
- License: Free for personal and commercial use. No signup, no attribution required.

## HTML

```html
<nav class="rail" aria-label="Main">
  <a href="#" aria-current="page">
    <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M3 11l9-8 9 8"/><path d="M5 10v10h14V10"/></svg>
    <span>Home</span>
  </a>
  <a href="#">
    <svg viewBox="0 0 24 24" aria-hidden="true"><circle cx="11" cy="11" r="7"/><path d="m20 20-3.5-3.5"/></svg>
    <span>Search</span>
  </a>
  <a href="#">
    <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M3 20h18M7 16V9M12 16V5M17 16v-4"/></svg>
    <span>Reports</span>
  </a>
  <a href="#">
    <svg viewBox="0 0 24 24" aria-hidden="true"><circle cx="12" cy="8" r="4"/><path d="M4 21a8 8 0 0 1 16 0"/></svg>
    <span>Profile</span>
  </a>
</nav>
```

## CSS

```css
.rail {
  display: flex;
  flex-direction: column;
  gap: 2px;
  box-sizing: border-box;
  width: 60px;
  padding: 8px;
  overflow: hidden;
  border-radius: 16px;
  background: #0f172a;
  transition: width 0.25s ease;
}

.rail:hover,
.rail:focus-within {
  width: 180px;
}

.rail a {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 9px 11px;
  border-radius: 10px;
  color: #94a3b8;
  font: 500 14px system-ui, sans-serif;
  text-decoration: none;
  white-space: nowrap;
}

.rail svg {
  flex: none;
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Labels stay in the accessibility tree, only faded out */
.rail span {
  opacity: 0;
  transition: opacity 0.2s ease;
}

.rail:hover span,
.rail:focus-within span {
  opacity: 1;
}

.rail a:hover,
.rail a[aria-current="page"] {
  background: #1e293b;
  color: #f8fafc;
}

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

@media (prefers-reduced-motion: reduce) {
  .rail,
  .rail span { transition: none; }
}
```

## Notes

- This CSS Expanding Icon Sidebar is 67 lines of pure CSS (1.1 KB) with no JavaScript and no dependencies. It uses transitions, Flexbox, keyboard focus styles and reduced-motion support.
- In JSX use `className` instead of `class`. In Tailwind projects put the CSS in the global stylesheet.
