An application sidebar built with Tailwind CSS that opens with a user profile header: a gradient cover strip, a round profile photo with an online dot, the name, the role and an "Edit profile" link. Below it, navigation links are grouped into collapsible sections, and the footer holds a help link and a logout button with an inline confirmation. It fits dashboards, SaaS admin areas and internal tools.
How it works
The root is div.tsp-app with a data-open attribute. It contains the aside#tsp-sidebar (.tsp-sidebar), a .tsp-backdrop for phones and the page area with a header and sample dashboard cards. The nav holds three .tsp-group blocks (Workspace, Team, Account). Each group heading is a button with aria-expanded and aria-controls that points to its ul; the chevron rotates through the group-aria-[expanded=false]/head:-rotate-90 variant. Links use aria-current="page" for the active item, which aria-[current=page]:bg-violet-50 turns into a violet highlight.
From the lg breakpoint the sidebar is a static column. Below it, style.css turns .tsp-sidebar into an off-canvas drawer that slides in when data-open="true". The script initializes each .tsp-app on DOMContentLoaded: .tsp-open opens the drawer and focuses the current link; any [data-tsp-close] element, the Escape key or choosing a link closes it and returns focus. Clicking a .tsp-link moves aria-current and copies its .tsp-label text into .tsp-title. The .tsp-logout button reveals the .tsp-confirm box with Cancel and Sign out buttons.
Customization
- The
imgin the profile header: replace the photo,alttext, name and role with the signed-in user's data. bg-linear-to-br from-violet-600 via-fuchsia-500 to-amber-300on the cover strip: pick your own gradient or a solidbg-zinc-900.aria-[current=page]:bg-violet-50 aria-[current=page]:text-violet-700on.tsp-link: change the active link colors.w-72on.tsp-sidebar: usew-64for a narrower column; the drawer width follows.aria-expanded="false"on a group button plushiddenon itsul: start that section collapsed.(max-width: 63.98rem)instyle.cssandDESKTOPinscript.js: switch both to48remto show the static sidebar from themdbreakpoint.- The
.tsp-logout-confirmclick handler inscript.js: call your sign-out endpoint or redirect to your logout URL.
Use cases
- SaaS dashboards: a profile header with photo, role and Edit profile link tops the sidebar
- Admin areas: link groups such as Workspace, Team and Account collapse to keep long menus tidy
- Internal tools: badges show unread counts next to menu items
- Mobile web apps: the sidebar becomes a slide-in drawer that closes with Escape or a backdrop click
- Account menus: the footer logout button asks for confirmation inline before signing out
Accessibility
The sidebar is an aside with aria-label="Sidebar" and a nav labelled "Main". Section buttons expose aria-expanded and aria-controls, the active link has aria-current="page", and badges include visually hidden text such as "3 unread". The online dot is decorative with a visually hidden "(online)" text. On phones the menu button reports aria-expanded, Tab is kept inside the open drawer, Escape closes it and focus returns to the menu button. The logout button exposes aria-expanded for its confirmation, and a role="status" region announces page changes and the demo sign out. All controls show visible focus rings, and the slide animation is disabled under prefers-reduced-motion.
Usage notes
The profile photo comes from Unsplash; replace it with your user's avatar. Real links should use real href values; the script only prevents navigation for href="#".