Sidebar Nav
A vertical nav with four links and a glowing indicator on the active one.
<nav class="w-full max-w-xs space-y-1 rounded-xl border border-slate-200 bg-white p-2 shadow-sm" aria-label="Sidebar">
<a href="#" class="relative flex items-center gap-3 rounded-lg bg-indigo-50 px-4 py-2.5 text-sm font-medium text-indigo-700">
<span class="absolute top-1/2 left-0 h-6 w-1 -translate-y-1/2 rounded-full bg-indigo-600"></span>
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="h-4 w-4"><rect x="3" y="3" width="7" height="7" rx="1.5"/><rect x="14" y="3" width="7" height="7" rx="1.5"/><rect x="3" y="14" width="7" height="7" rx="1.5"/><rect x="14" y="14" width="7" height="7" rx="1.5"/></svg>
Dashboard
</a>
<a href="#" class="flex items-center gap-3 rounded-lg px-4 py-2.5 text-sm text-slate-600 transition-colors hover:bg-slate-50 hover:text-slate-900">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="h-4 w-4"><path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"/><circle cx="9" cy="7" r="4"/><path d="M23 21v-2a4 4 0 0 0-3-3.87M16 3.13a4 4 0 0 1 0 7.75"/></svg>
Team
</a>
<a href="#" class="flex items-center gap-3 rounded-lg px-4 py-2.5 text-sm text-slate-600 transition-colors hover:bg-slate-50 hover:text-slate-900">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="h-4 w-4"><path d="M3 3v18h18"/><path d="M7 15l4-6 4 3 5-8"/></svg>
Reports
</a>
<a href="#" class="flex items-center gap-3 rounded-lg px-4 py-2.5 text-sm text-slate-600 transition-colors hover:bg-slate-50 hover:text-slate-900">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="h-4 w-4"><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 1 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 1 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 1 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 1 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"/></svg>
Settings
</a>
</nav>Free to use in personal and commercial projects. No attribution required.
Variants
Same component, different looks. Preview each one live and copy the code you like.
Dark
The dark sidebar fits admin panels and dashboards with a dark theme.
With badges
Badges surface counts like pending invites or unread reports without leaving the nav.
Emerald
The emerald active state suits eco, finance, and health dashboards with a green brand.
About this sidebar nav
Dashboard sidebars live or die on one question: where am I? This vertical nav answers it three ways at once. The active link gets a tinted background, a darker indigo text color, and a slim indicator bar pinned to its left edge, so the current section is unmistakable at a glance.
Each link is a flex row with a 16px icon and a label, padded generously for touch targets. The indicator is an absolutely positioned rounded bar, vertically centered, which is a lighter touch than a full-height border. Inactive links stay quiet gray and warm to a slate hover, keeping the hierarchy clear.
Use it for admin panels, settings pages, and docs sidebars. Mark the current page with aria-current="page" on the active link so screen readers announce it, and move the active classes to whichever link matches the route.
In admin panels, a lost user is an expensive user: every moment spent hunting for the right section is a support ticket waiting to happen. New team members facing an unfamiliar dashboard do not read documentation; they scan the left edge for something recognizable. A sidebar that clearly marks the current location cuts onboarding time because the interface teaches itself. The alternative is a flat list of identical links where every page feels the same and nobody knows where they are.
The active indicator is an absolutely positioned bar, not a background on the link itself, which keeps the highlight crisp when labels vary in length. It centers vertically on the active link with top-1/2 and -translate-y-1/2, so it tracks correctly even if link heights change. Using a bar instead of a full-row background is deliberate restraint: a filled row screams, a 3px bar whispers, and navigation should whisper. The bar animates between links with a top transition, turning navigation into a small moment of continuity.
When a child page is open, keep its parent section highlighted too, so the trail reads Settings, Notifications instead of just Notifications. Add keyboard shortcut hints to power-user links for the dashboard crowd that lives in the app. Sort links by frequency of use, not alphabetically; the top three links earn the vast majority of clicks.
The lying indicator is the subtle failure: in single-page apps the active style is set once on load and never updates as the user navigates, so the sidebar insists you are on Dashboard while you are staring at Billing. Recompute the active link on every route change, and match exact paths before falling back to prefixes, or two sections will light up at once. A nav that misreports location is worse than one with no indicator.
Where to use it
- ✓ Admin dashboard sidebars
- ✓ Account settings navigation
- ✓ Documentation sidebars
- ✓ App settings panels
Customization tips
Move the indicator to the right edge for RTL layouts. Add badge counts (like unread notifications) with an ml-auto pill on any link. Collapse to icon-only on small screens with a toggle that hides the labels.
Design notes
When to use
A sidebar nav fits apps with five to ten top-level sections that users jump between all day, like dashboards and admin panels. The persistent rail keeps navigation one click away no matter how deep the content scrolls. The glowing active indicator answers where am I without reading a single label, which matters when users live in the app for hours.
What to avoid
Do not use a sidebar for three sections, a top bar is simpler and wastes less horizontal space. Avoid cramming twenty links into it, at that scale you need grouped sections or search. And do not hide the labels behind icons alone unless your users truly live in the app, newcomers will be lost.
Accessibility
Mark the nav with an aria-label and the current link with aria-current so screen reader users know their location. Keep the full labels visible or at least available, since icon-only navigation is a guessing game.
Frequently asked questions
How do I highlight the active link in a sidebar?
Combine three signals: a tinted background, a stronger text color, and an indicator bar. One signal alone is easy to miss; three together make the active state obvious without reading.
Should sidebar links be buttons or anchors?
Use anchors when they navigate to a new page or route, buttons when they switch views without navigation. Here they are anchors because each goes to a different page.
How do I make this accessible?
Wrap the links in a nav with an aria-label, and put aria-current="page" on the active link. Keep the visible focus ring so keyboard users can see where they are.
How do I turn the sidebar into a mobile drawer?
Below your breakpoint, position the sidebar fixed and off-canvas with -translate-x-full, then slide it to translate-x-0 when the hamburger is tapped. Add a backdrop overlay that closes the drawer on click. Lock body scroll while it is open so the page behind does not move.
How do I make a collapsible sidebar that shrinks to icons?
Animate the sidebar width between full and icon-only sizes, and hide the text labels with opacity and whitespace nowrap when collapsed. Keep tooltips on the icons so collapsed labels are still discoverable. Persist the collapsed state in localStorage so it survives reloads.
How do I add section labels inside a sidebar nav?
Group links under small uppercase headings like Main and Settings using a plain list with a heading element or aria-labelledby. Keep labels short, one or two words, and style them in a muted small caps so they read as dividers, not links. Do not make section labels clickable.