Skip to content
IndexRequest a UIAboutContact

Sidebar

A vertical navigation that collapses to an icon rail and expands on demand.

Open alone ↗

AI prompt

PROMPT: PASTE INTO YOUR AI CODING TOOL
Build a collapsible sidebar navigation with five items (Overview, Projects, Messages, Reports, Settings), each an inline SVG icon plus a label. Expanded width is 220px; collapsed width is 64px showing only icons. A toggle button at the top switches modes using aria-expanded, animating width over 260ms with cubic-bezier(0.4,0,0.2,1); labels fade out in 120ms. The current item has a 3px accent bar on its left edge and aria-current="page". In the collapsed state each item shows a tooltip to its right on hover and keyboard focus, using the label text; set aria-label on each item so the name is available when text is hidden. Hover lightens the item surface. Persist nothing; keep state in JS. Make the layout work in a 520px-wide demo frame. Respect prefers-reduced-motion by removing the transition.

About this pattern

Definition

A vertical list of destinations pinned to the left edge. It has two widths: an expanded form with icons and labels and a collapsed rail with icons only, toggled by a button.

Purpose & UX principles

  • Suits products with many sections, because a vertical list scales to dozens of items where a top bar cannot.
  • The collapsed rail keeps navigation available while giving the workspace more room.
  • In the rail, every icon needs an accessible name and a tooltip, since the label is hidden.

Interaction states

  • Expanded and collapsed, stored in aria-expanded on the toggle.
  • Item hover: surface lightens.
  • Current item: accent bar on the left edge, brighter text, aria-current="page".
  • Collapsed item hover: a tooltip with the label appears to the right.

Motion specification

  • Width: 260ms cubic-bezier(0.4, 0, 0.2, 1).
  • Labels: fade out in 120ms before the width finishes shrinking.
  • Toggle icon: rotates 180deg in 260ms.
  • Reduced motion: width snaps with no animation.

Responsive behaviour

  • Desktop: expanded by default at 220px, collapsible to 64px.
  • Tablet: start collapsed.
  • Phone: replace with a drawer opened from a menu button, or with a bottom navigation.

Code

HTML
<div class="shell">
  <aside class="side" id="side" aria-label="Sidebar">
    <button class="toggle" id="tg" aria-expanded="true" aria-label="Collapse sidebar"><svg viewBox="0 0 24 24"><path d="M15 6l-6 6 6 6"/></svg></button>
    <a href="#" class="item" aria-current="page" aria-label="Overview"><svg viewBox="0 0 24 24"><path d="M4 4h7v7H4zm9 0h7v7h-7zM4 13h7v7H4zm9 0h7v7h-7z"/></svg><span>Overview</span></a>
    <a href="#" class="item" aria-label="Projects"><svg viewBox="0 0 24 24"><path d="M3 6h7l2 2h9v11H3z"/></svg><span>Projects</span></a>
    <a href="#" class="item" aria-label="Messages"><svg viewBox="0 0 24 24"><path d="M3 5h18v12H8l-5 4z"/></svg><span>Messages</span></a>
    <a href="#" class="item" aria-label="Reports"><svg viewBox="0 0 24 24"><path d="M5 20V10h3v10zm5 0V4h3v16zm5 0v-7h3v7z"/></svg><span>Reports</span></a>
    <a href="#" class="item" aria-label="Settings"><svg viewBox="0 0 24 24"><path d="M12 8a4 4 0 100 8 4 4 0 000-8zm-1-6h2l.5 3 2 1 2.7-1.5 1.4 1.4L18 8.5l1 2 3 .5v2l-3 .5-1 2 1.6 2.6-1.4 1.4L15.5 18l-2 1-.5 3h-2l-.5-3-2-1-2.7 1.6-1.4-1.4L6 15l-1-2-3-.5v-2l3-.5 1-2-1.6-2.6 1.4-1.4L8.5 6l2-1z"/></svg><span>Settings</span></a>
  </aside>
  <section class="main"><h2>Workspace</h2><p>Collapse the sidebar to get more room.</p></section>
</div>

Related patterns

Top Navigation

↗
Top NavigationNavigation

Drawer

↗
DrawerOverlays & Dialogs

Tab Navigation

↗
Tab NavigationNavigation