AppShell
Header / sidebar / main app frame on CSS Grid named areas. Sidebar scrolls its own content with a pinned header/footer, can collapse on desktop with a hover-to-peek card, and becomes an overlay Drawer on mobile.
AppShell is a composable app frame: Header + Sidebar + Main + Aside, laid out with grid-template-areas. Sidebar and Aside each span the full height, on the left and right; Header sits only in the middle column, above Main. There's no Footer and no variant/color axis — like Table/Grid/Flex, it's a structural primitive, not a themed surface.
import { AppShell } from "@42-central/ui-react/app-shell";
<AppShell>
<AppShell.Sidebar>
<AppShell.SidebarHeader>Logo</AppShell.SidebarHeader>
<AppShell.SidebarBody>{/* nav — scrolls */}</AppShell.SidebarBody>
<AppShell.SidebarFooter>{/* user menu */}</AppShell.SidebarFooter>
</AppShell.Sidebar>
<AppShell.Header>
<AppShell.SidebarTrigger asChild>
<ActionIcon variant="subtle" color="neutral">
<PanelLeft />
</ActionIcon>
</AppShell.SidebarTrigger>
</AppShell.Header>
<AppShell.Main>Page content</AppShell.Main>
<AppShell.Aside>{/* e.g. an on-this-page rail */}</AppShell.Aside>
</AppShell>;AppShell fills the viewport (h-dvh) by default — every example below overrides that with a fixed height so it fits the doc page instead. For the real thing, full-page and unbounded:
View full-page example
Basic
Code
<AppShell className="h-[28rem] rounded-lg border border-brand-900/10 dark:border-white/8">
<AppShell.Sidebar>
<AppShell.SidebarHeader>Logo</AppShell.SidebarHeader>
<AppShell.SidebarBody>Nav</AppShell.SidebarBody>
<AppShell.SidebarFooter>User menu</AppShell.SidebarFooter>
</AppShell.Sidebar>
<AppShell.Header>
<AppShell.SidebarTrigger asChild>
<ActionIcon variant="subtle" color="neutral"><PanelLeft /></ActionIcon>
</AppShell.SidebarTrigger>
</AppShell.Header>
<AppShell.Main>Page content</AppShell.Main>
</AppShell>Sidebar scrolls independently, header/footer stay pinned
SidebarHeader and SidebarFooter are plain flex siblings either side of SidebarBody, which is the only part that scrolls: a vertical ScrollArea whose edges fade only where there is more to scroll to. There's no position: sticky involved — the header/footer simply aren't inside the scroll region.
Code
<AppShell className="h-[28rem] ...">
<AppShell.Sidebar>
<AppShell.SidebarHeader>Logo</AppShell.SidebarHeader>
<AppShell.SidebarBody>
{items.map((item) => (
<NavLink key={item.label} label={item.label} startSlot={item.icon} linkOptions={{ href: item.href }} />
))}
</AppShell.SidebarBody>
<AppShell.SidebarFooter>User menu</AppShell.SidebarFooter>
</AppShell.Sidebar>
{/* … */}
</AppShell>Collapsible sidebar
Render an AppShell.SidebarCollapseTrigger and the desktop sidebar becomes collapsible, the way the sidebar of these docs is. The trigger is the opt-in: a shell without one, and without a collapsed prop, never collapses. When it collapses, its grid column animates to zero and the sidebar slides off the start edge, so Header and Main take the full width. While it's collapsed, rest the pointer on that edge and the sidebar slides back in as a floating card over the page. Leave toward the page and it hides at once. Leave near the edge, overshooting it for example, and it waits half a second before going.
SidebarCollapseTrigger mirrors SidebarTrigger. It renders nothing below breakpoint, where the sidebar is a drawer, just as SidebarTrigger renders nothing above it. Usually there are two: one in SidebarHeader to collapse, and one in Header to bring the sidebar back. The one in the sidebar slides away with it. Render the Header one only while useAppShell().collapsed is true, so it doesn't duplicate the other.
Code
function ExpandSidebar() {
const { collapsed } = useAppShell()
if (!collapsed) return null
return (
<AppShell.SidebarCollapseTrigger asChild>
<ActionIcon variant="subtle" color="neutral" aria-label="Expand sidebar"><PanelLeftOpen /></ActionIcon>
</AppShell.SidebarCollapseTrigger>
)
}
<AppShell>
<AppShell.Sidebar aria-label="Main navigation">
<AppShell.SidebarHeader className="justify-between">
<Logo />
<AppShell.SidebarCollapseTrigger asChild>
<ActionIcon variant="subtle" color="neutral" aria-label="Collapse sidebar"><PanelLeftClose /></ActionIcon>
</AppShell.SidebarCollapseTrigger>
</AppShell.SidebarHeader>
{/* … */}
</AppShell.Sidebar>
<AppShell.Header>
<ExpandSidebar />
{/* … */}
</AppShell.Header>
<AppShell.Main>Page content</AppShell.Main>
</AppShell>While collapsed, the sidebar is inert: its links can't be tabbed to and aren't read out until it's back on screen. Collapsing from the trigger inside it moves focus to the collapse trigger outside it, even one like ExpandSidebar above that only just rendered, so keyboard focus is never dropped. Touch doesn't peek, since there's no hover to end it; on a touch screen the Header trigger is the way back. In a right-to-left page everything flips to the right edge.
Icon rail
Give Sidebar collapse="icons" and collapsing shrinks it to a 68px rail of icons instead of hiding it. The collapsed state, the trigger and useAppShell are the same as for hiding (collapse="hide", the default). The rail stays on screen and usable: its trigger stays where it is, so no Header button is needed, and focus doesn't move.
NavLinkrows show theirstartSlotalone. The label stays as the accessible name and shows as a tooltip on hover or keyboard focus.endSlot, chevrons and nested rows hide until the labels are back.- Resting the pointer on the rail widens it to the full sidebar over the page, with labels and nested rows, until the pointer leaves. It has to stay still for 1.2s: any movement restarts the count, so moving across the icons and reading their tooltips never opens it, and only a deliberate pause does. The demo below nests a few rows under Projects and Evaluations. They hide on the rail and come back with the peek.
- Nothing moves while it opens and closes. The rail is exactly as wide as the expanded sidebar's icon column (SidebarBody's padding plus a row's, each side of the icon), so every icon stays where it is and only the width animates. Keep that true for your own content: hide what doesn't fit rather than re-laying it out for the rail, and end-align a header trigger (
ms-auto) so it follows the edge. A logo next to it should sit in amin-w-0 overflow-hiddenwrapper, so the widening edge reveals it instead of it pushing the trigger aside. Text that reappears, like a footer's user name, should not wrap (whitespace-nowrap): it shows while the rail is still narrow, and wrapping would grow the footer mid-transition and push the list. - Anything else that doesn't fit, like a logo's wordmark or a footer's user name, hides with the
sidebar-rail:variant. It ships in the kit'stheme.cssand matches anything inside a sidebar showing icons only:
<AppShell.Sidebar aria-label="Main navigation" collapse="icons">
<AppShell.SidebarHeader className="justify-between">
<Logo className="sidebar-rail:hidden" />
<AppShell.SidebarCollapseTrigger asChild>
<ActionIcon className="ms-auto" variant="subtle" color="neutral" aria-label="Toggle sidebar"><PanelLeft /></ActionIcon>
</AppShell.SidebarCollapseTrigger>
</AppShell.SidebarHeader>
{/* … */}
<AppShell.SidebarFooter>
<Avatar />
<span className="sidebar-rail:hidden">Ada Lovelace</span>
</AppShell.SidebarFooter>
</AppShell.Sidebar>Code
<AppShell.Sidebar aria-label="Main navigation" collapse="icons">…</AppShell.Sidebar>Remembering it, and a shortcut
The state is a controlled pair on the root: collapsed, defaultCollapsed and onCollapsedChange. useAppShell() also exposes collapsed and setCollapsed to any descendant. The kit doesn't decide whether the choice survives a reload, or which key toggles it. Both take a line each:
import { useHotkey, useLocalStorage } from "@42-central/ui-react";
function Shell({ children }) {
const [collapsed, setCollapsed] = useLocalStorage({ key: "sidebar-collapsed", defaultValue: false });
return (
<AppShell collapsed={collapsed} onCollapsedChange={setCollapsed}>
{children}
</AppShell>
);
}
// Anywhere under <AppShell>:
function SidebarShortcut() {
const { setCollapsed } = useAppShell();
useHotkey("mod+b", () => setCollapsed((value) => !value));
return null;
}useLocalStorage renders defaultValue on the server and on the first client render, then switches to the stored value. A visitor who left the sidebar collapsed sees it collapse once just after the page loads.
Mobile
On desktop, Sidebar is a grid column (collapsible, if you opt in). Below breakpoint (default 768 px), it stops rendering as a grid column and mounts through the kit's own Drawer instead, full width, opening from the end edge (the right, in LTR), with the same SidebarHeader/SidebarBody/SidebarFooter layout carried over: only the body scrolls, header and footer stay pinned. AppShell.SidebarTrigger renders nothing on desktop (nothing to toggle) and opens/closes the Drawer on mobile.
The mobile drawer has no title, so give Sidebar an aria-label (say, "Main navigation"): it names the <aside> on desktop and the drawer on mobile. Without one, the drawer is a dialog with no accessible name, and Drawer warns in development.
breakpoint is measured against AppShell's own rendered width (via ResizeObserver), not the browser viewport — so this switches correctly even when AppShell is embedded in a panel, a resizable pane, or anything narrower than the window, not just when it fills the whole page.
At full width there's no backdrop sliver left to tap and no button elsewhere on screen to close it (the trigger that opened it, in Header, is now covered) — swipe-to-dismiss on the Drawer's content works, but a gesture with no visual cue isn't enough on its own, especially over a sidebar full of tappable nav rows. Render a second SidebarTrigger inside SidebarHeader itself, styled as a close icon — it's a no-op on desktop (nothing renders), and on mobile it puts a visible, reachable close control right in the panel that's actually on screen:
<AppShell.SidebarHeader className="justify-between">
<Logo />
<AppShell.SidebarTrigger asChild>
<ActionIcon variant="subtle" color="neutral" aria-label="Close sidebar">
<X />
</ActionIcon>
</AppShell.SidebarTrigger>
</AppShell.SidebarHeader>Navigating from the drawer
Following a link inside the mobile drawer closes it — the same thing a full page load would have done, which a client-side router never does. Any plain click on an <a href> in the drawer counts, whether a router's Link or a bare anchor rendered it; a modified click (⌘/Ctrl/Shift-click to open a new tab) leaves the drawer open, since this page didn't change. Nothing to wire up.
For navigation a link click didn't cause — a form that submits and then calls router.push — close it yourself with useAppShell, from anywhere under <AppShell>:
import { useAppShell } from "@42-central/ui-react/app-shell";
function SaveButton() {
const { setMobileOpen } = useAppShell();
return (
<Button
onClick={async () => {
await save();
router.push("/done");
setMobileOpen(false);
}}
>
Save
</Button>
);
}Resize your browser under 768px against the Basic example above to see it (the frame itself narrows along with the window), or force it regardless of size with an unreachable breakpoint (demo-only trick — pick a real value like the default in production):
Code
<AppShell breakpoint={2000} className="h-[28rem] ...">
{/* forces mobile mode regardless of AppShell's rendered width, for this demo only */}
</AppShell>Aside
The right-hand counterpart to Sidebar — e.g. for an on-this-page/table-of-contents rail. Unlike Sidebar, which spans the full height beside Header, Aside sits below Header (Header spans the rest of the top row above both Main and Aside). It also carries no border or background of its own — a plain content region, styled the same as Main.
Aside is also always mounted: no useContainerQuery, no context, no client state deciding whether it renders at all. It's hidden below a @xl container breakpoint (1280px of AppShell's own rendered width — its grid root carries @container, and Tailwind's native container-query variants read against that) and shown above it purely via static classes (hidden @xl:flex), mirroring how fumadocs' own docs layout keeps its table-of-contents rail always in the DOM rather than conditionally unmounting it — nothing here can ever produce a hydration mismatch, since nothing renders differently based on client-only state. Sidebar can't do the same, because it has two genuinely different structural forms (a plain <aside> vs. a portaled Drawer dialog) — keeping both always mounted would mean duplicating whatever's inside Sidebar into two simultaneous trees. Aside only has one form, so there's nothing to duplicate.
Because it's a container query, not a viewport one, widening your browser only matters here to the extent it widens this bounded preview frame — it's AppShell's own width that's being measured. The full-page example fills the real viewport, so resizing the actual window is the reliable way to see it switch live.
Code
<AppShell className="h-[28rem] ...">
{/* … */}
<AppShell.Aside>
<div className="p-4">On this page…</div>
</AppShell.Aside>
</AppShell>Content column
Main puts its children in a centered content column by default, so a page of prose and forms doesn't stretch to whatever width the window happens to be. Space-hungry blocks — a data table, a carousel, a hero, a full-width background — opt out of it explicitly with AppShell.Full, and AppShell.Content puts arbitrary content back in.
Nothing needs a wrapper: Main supplies the column and its own block padding, so the <div className="p-4"> that used to line every page goes away.
Quarterly sales
Prose sits in the column, so a line of text never stretches to whatever width the window happens to be.
| Region | Owner | Pipeline | Closed | Win rate |
|---|---|---|---|---|
| Île-de-France | Ada Lovelace | €1.24M | €820K | 64% |
| Auvergne-Rhône-Alpes | Grace Hopper | €980K | €612K | 58% |
| Occitanie | Katherine Johnson | €745K | €498K | 61% |
| Hauts-de-France | Radia Perlman | €631K | €334K | 47% |
The band's fill runs edge to edge…
…while AppShell.Content puts its text back on the column's edges — flush with the paragraphs above and below, with no max-width of its own to keep in sync.
Back in the column, with no wrapper to close.
Code
<AppShell.Main>
<Title order={2}>Quarterly sales</Title>
<Text>Prose sits in the column.</Text>
{/* Out to Main's real width — the table gets every pixel */}
<AppShell.Full asChild>
<Table size="sm" striped>
<Table.Content>{/* … */}</Table.Content>
</Table>
</AppShell.Full>
{/* The band's fill runs edge to edge; its text goes back on the column */}
<AppShell.Full asChild>
<section className="border-y bg-(--c-soft) py-5" data-color="purple">
<AppShell.Content>
<Text>Flush with the paragraphs above and below.</Text>
</AppShell.Content>
</section>
</AppShell.Full>
<Text>Back in the column, with no wrapper to close.</Text>
</AppShell.Main>Two things about that frame are staged, and neither is how you'd write it. It drops the Sidebar, because a nav rail would only eat the width the demonstration needs — these previews are bounded to about 720px whatever your window is doing, and every pixel the sidebar takes comes out of Main. And the measure is overridden to 26rem, because the real default is 1280px, so at this size nothing here would be constrained and you'd be looking at a column that never engages. --app-shell-measure is a plain inherited custom property, which is what makes that override a one-liner. The full-page example runs the real default.
How it works, and what that buys
Main is three grid tracks — 1fr, the column, 1fr — rather than a box with inline padding. Spanning all three is what takes a child to the edges, so there are no negative margins, no 100vw (which mismeasures whenever a scrollbar is present), and no JavaScript measuring anything.
Percentages in grid track sizing resolve against Main's own content box, so the column is correct beside a sidebar, inside a resizable pane, or in a bounded frame like the preview above — no media query and no ResizeObserver involved. And because the middle track is min(100% - 2 × gutter, measure), the column narrows into plain padding continuously as space runs out, rather than snapping at a breakpoint.
Two things follow from it being a grid:
AppShell.Fullonly works as a direct child ofMain. Breaking out of a grid means being in it. For deeper content, make aFullband and useAppShell.Contentinside it.AppShell.Contentworks at any depth, because it re-derives the column's width from the inherited--app-shell-measure/--app-shell-gutterrather than from the grid. It is also the way to get the column inside afluidMain.
AppShell.Full sets no class of its own — it marks itself data-full, and Main's own rule places it. With asChild that marker merges onto your component, so a breakout costs nothing in the DOM.
Sizing and opting out
size picks the measure from the kit's --width-* tokens: sm 48rem, md 64rem, lg 80rem (the default), xl 90rem. For a one-off, set --app-shell-measure or --app-shell-gutter through className — the gutter also drives Main's block padding.
fluid drops the column entirely, restoring an edge-to-edge Main. Use it when Main is one full-canvas component rather than a document — a Schedule, or a DataTable sized to the viewport:
<AppShell.Main fluid>
<Schedule data={events} />
</AppShell.Main>A single full-height child needs this rather than AppShell.Full: Main stacks its rows with align-content: start (otherwise grid hands leftover vertical space to every row and spaces a short page out down the viewport), and a child cannot resolve h-full against an auto row. fluid removes the grid, so h-full resolves against Main itself again.
Vertical rhythm is left alone — Main sets no row gap, so add className="gap-6" if you want one.
Subcomponents
Prop
Type
API
AppShell
Prop
Type
AppShell.Main
Prop
Type
useAppShell
Reads the shell's sidebar state from any descendant of <AppShell> (it throws outside one).
Prop
Type
Accessibility
SidebarTriggeris a disclosure button:aria-expandedfollows the mobile drawer, andaria-controlsnames the drawer's content.SidebarCollapseTriggeris a disclosure button too:aria-expandedis true while the desktop sidebar is expanded.- On an icon rail, each
NavLink's label stays its accessible name, so screen readers read the same names as when expanded. - A sidebar collapsed with
collapse="hide"isinert, so nothing in it takes focus or is read out until it's expanded or peeking. Collapsing from inside it hands focus to a collapse trigger outside it. - The mobile drawer is a modal dialog named by
Sidebar'saria-label/aria-labelledby— give it one. - Following a link inside the drawer closes it, so focus and the screen reader's virtual cursor land on the new page rather than on a dialog that's still covering it.
Changelog
- #500
With
scrollbars="y", the content keeps the viewport's width, so a long row truncates instead of clipping every row;AppShell.SidebarBodyrows truncate again
- #494
Sidebar.Bodyscrolls with the kit's scrollbars; its edge fade shows only where more links are hidden, and in the mobile drawer the sidebar header and footer stay put
- #448
The desktop sidebar collapses:
AppShell.Sidebar'scollapseprop picks"hide"(slides off, peeks back on hover) or"icons"(a 68px icon rail), driven by the newAppShell.SidebarCollapseTriggerandcollapsed/defaultCollapsed/onCollapsedChange
- #383
Drawer, Modal and
AppShell.Sidebaracceptaria-label/aria-labelledby, and development warns when an open dialog has no accessible name - #389
The mobile drawer closes when a link inside is followed,
SidebarTriggerexposesaria-expanded/aria-controls, anduseAppShell()returnsmobileOpen,setMobileOpen,isMobileandsidebarId - #384
A callback
refis no longer detached and re-attached on every render
- #294
asChildis a compile error on the data forms ofAccordion,TabsandBreadcrumb, on the ready-madeNotificationand onAppShell.Sidebar(theirRootparts keep it)
- #177
Main gains a content column with an explicit breakout
- #47
Header and Sidebar chrome take the brand tint, and SidebarHeader drops its bottom border
- #37
Header and the sidebar header draw their bottom borders
- #19
New
AppShell: Header, Sidebar, Main and Aside on CSS Grid, responsive to its container, not the viewport
Splitter
Resizable panes. Two or more panels share a box, and the user drags the line between them, or uses the keyboard, to give one more room.
AmbientBackground
A decorative, brand-tinted page background — a soft radial glow plus a fine noise texture — so a flat page fill reads as a considered surface instead of a plain color.