Skip to content

Site shell

Build the header, footer, theme and skip link of a site with SiteShell, SiteShellStatic and the theme cookie of VLLNT UI.

The site shell is the frame around every page of a site: a skip link, a header, the page in main, a footer and, if you want one, a theme control. You pass the header, the footer and their text; the shell decides the order and where each part sits. The library holds no brand, link or copy: every name, URL and label comes from your app.

PartWhat it does
SiteShellThe whole shell for an app that hydrates: theme provider, skip link, header, main#main, footer, theme control.
SiteShellStaticThe same order for a page whose shell needs no hydration. No settings, no theme control.
SiteHeaderThe header: brand, links, menu, language link, button, site switcher. A client component.
SiteHeaderStaticThe same header as a server component. The menu and the switcher are native popovers.
SiteFooterA brand block with a tagline, one to five link columns and an optional bottom row.
SiteFrame, SiteThemeProviderThe theme provider and skip link alone, for your own composition.
ShellLinkEventsReports clicks on shell links, for your analytics.
@vllnt/ui/theme-cookieThe theme cookie script and writer for a page with no React.

Minimal setup

Install the package, then render the shell inside body in your root layout. The app keeps html, body, its fonts and its own providers.

pnpm add @vllnt/ui
// app/layout.tsx import { SiteFooter } from "@vllnt/ui/site-footer"; import { SiteHeader } from "@vllnt/ui/site-header"; import { SiteShell } from "@vllnt/ui/site-shell"; export default function RootLayout({ children }: { children: React.ReactNode }) { return ( <html lang="en" suppressHydrationWarning> <body> <SiteShell header={ <SiteHeader brand="Acme" homeHref="/" items={[ { bar: "tablet", href: "/guides", label: "Guides" }, { bar: "desktop", href: "/pricing", label: "Pricing" }, { href: "/about", label: "About" }, ]} labels={{ close: "Close menu", home: "Acme home", menu: "Menu", open: "Open menu", primary: "Primary", }} /> } footer={ <SiteFooter brand="Acme" columns={[ { heading: "Product", id: "product", links: [{ href: "/pricing", label: "Pricing" }] }, ]} navLabel="Footer" otherSite="other site" tagline="Tools for builders." /> } settings={{ theme: { label: "Theme", options: { dark: "Dark", light: "Light", system: "System" } }, }} skipLabel="Skip to content" > {children} </SiteShell> </body> </html> ); }
  • suppressHydrationWarning on html is needed because the theme provider sets the dark or light class there before React hydrates.
  • brand is required on the header and the footer. There is no default brand.
  • Without settings.theme the site has no theme control and follows the system.
  • Import each part from its subpath (@vllnt/ui/site-shell, not @vllnt/ui). From the root, a Next.js page ships the client code of the whole library: see the measurements under the static recipe.

Recipes

A page with a static header

SiteShellStatic and SiteHeaderStatic render the same shell from server components. The menu and the site switcher are buttons that open native popovers, so the header has no state, effect or event handler.

import { SiteFooter } from "@vllnt/ui/site-footer"; import { SiteHeaderStatic } from "@vllnt/ui/site-header-static"; import { SiteShellStatic } from "@vllnt/ui/site-shell-static"; <SiteShellStatic header={ <SiteHeaderStatic brand="Acme" currentHref="/guides" homeHref="/" items={[{ bar: "tablet", href: "/guides", label: "Guides" }]} labels={{ home: "Acme home", menu: "Menu", open: "Open menu", primary: "Primary" }} /> } footer={<SiteFooter {...footer} />} skipLabel="Skip to content" > {children} </SiteShellStatic>
  • Pass currentHref: a server component cannot read the browser path, so without it no link is marked current.
  • SiteHeaderStatic has no actions slot, no labels.close and no onClick on the language link. It adds status, a node beside the brand.

What reaches the browser, measured with next build and webpack (Next.js 16; Turbopack, its default bundler, was not measured) on a page that imports each part from its subpath:

What the page rendersJavaScript beyond an empty Next.js page (gzip)
SiteHeaderStatic aloneNone: the page loads the same files as an empty page.
SiteFooterAbout 10 KB: next/link, which its internal links use.
SiteShellStatic, with or without themeCookieAbout 12 KB: the next-themes provider. Adding SiteFooter adds nothing measurable.
Any of the above, imported from the root @vllnt/uiAbout 500 KB more, as soon as the page renders one client component (#882).

So the header itself ships no JavaScript, and the shell ships only its theme provider, if you import each part from its subpath:

import { SiteFooter } from "@vllnt/ui/site-footer"; import { SiteHeaderStatic } from "@vllnt/ui/site-header-static"; import { SiteShellStatic } from "@vllnt/ui/site-shell-static";

From the root @vllnt/ui, Next.js treats every client module the root re-exports as part of the page, so the first client component on the page (the shell's theme provider, the footer's next/link) brings them all. experimental.optimizePackageImports did not change that in this test (#882). Turbopack was not measured. Every App Router page also loads the Next.js runtime (about 170 KB gzip here), whatever the shell does; the theme script and the cookie seed are small inline scripts in the HTML.

Network switcher

Pass network to the header and the title becomes a button that opens a list of your sites. You build the groups from your own list; the library holds none.

<SiteHeader brand="Acme Docs" homeHref="/" network={{ label: "Acme network", groups: [ { id: "current", items: [{ current: true, href: "https://docs.example.com", label: "Acme Docs" }] }, { id: "products", heading: "Products", items: [ { current: false, href: "https://app.example.com", label: "Acme App", description: "Build and ship", status: "Beta" }, { current: false, href: "https://blog.example.com", label: "Acme Blog", mark: "EN", hrefLang: "en" }, ], }, ], }} /* items, labels */ />
  • A row marked current keeps its place and links to homeHref, not to its own href.
  • Each group id must be unique and have no spaces: it builds the ids of the headings and descriptions.
  • description, status and mark are display text in the page's language. description and status are read as the link's description; mark is part of its name (Acme Blog EN).
  • renderNetworkLabel draws each row with your own lockup. The lockup is decorative, so keep its visible text the same as label. SiteHeader is a client component: pass the function from a "use client" file. On SiteHeaderStatic it runs on the server while the page renders.

Footer links

<SiteFooter brand="Acme" tagline="Tools for builders." navLabel="Footer" otherSite="other site" columns={[ { heading: "Product", id: "product", links: [{ href: "/pricing", label: "Pricing" }] }, { heading: "Sites", id: "sites", links: [{ external: true, href: "https://docs.example.com", label: "Docs" }], }, ]} bottom={<p>© Acme</p>} />
  • One to five columns. Up to four share four tracks, so a column is as wide on every site.
  • A link marked external is a plain anchor with a ↗ and the otherSite text for screen readers. Other links go through next/link.
  • bottom adds a row under the columns, e.g. the legal line.

Shared theme with a cookie

By default each app keeps the visitor's theme in its own localStorage. themeCookie keeps it in a cookie you name, so apps on one site (example.com, docs.example.com) open in the same theme with no flash.

// An app with a theme control: reads the cookie before the first paint, writes it on change. <SiteShell themeCookie={{ domain: ".example.com", name: "site-theme" }} {...shell} /> // A static page: reads only, so it takes only the name. <SiteShellStatic themeCookie={{ name: "site-theme" }} {...shell} />
  • The cookie is written when the visitor changes the theme, never on a plain visit. A value that is not a known theme is ignored.
  • name uses letters, digits, _ and -. A bad name, domain or maxAge throws a TypeError when the page renders.
  • Leave domain out on localhost: a browser drops a domain that is not a parent of the page.

For a page with no React (plain HTML, a static site, another framework), import from @vllnt/ui/theme-cookie, which pulls in no React. themeCookieScript returns the same seed script the shells run; with attribute it also paints <html>. themeCookieString returns the text to assign to document.cookie when your own control changes the theme.

// build.mjs, run at build time import { writeFileSync } from "node:fs"; import { themeCookieScript } from "@vllnt/ui/theme-cookie"; writeFileSync( "public/theme.js", themeCookieScript({ attribute: "class", enableSystem: true, name: "site-theme", storageKey: "theme", themes: ["light", "dark"], }), );
<head> <script src="/theme.js"></script> </head>
import { themeCookieString } from "@vllnt/ui/theme-cookie"; document.cookie = themeCookieString( { domain: ".example.com", name: "site-theme" }, "dark", location.protocol === "https:", );

Pass the same name, storageKey, themes and enableSystem as your React apps (the shells use "theme", ["light", "dark"] and true).

Do not set themeCookie twice

Warning. Set themeCookie on one provider only: the outermost one. If your app wraps the shell in any theme provider, a SiteThemeProvider or a plain next-themes ThemeProvider, leave the prop off the shell.

The shell has no storageKey, themes or enableSystem props, so themeCookie on a shell inside another provider adds a seed script with the default settings. next-themes keeps the outer provider and ignores the inner one, but the shell's seed still runs. With an outer provider that has enableSystem={false} and the default storageKey, this breaks the stored theme:

// Wrong: themeCookie on both <SiteThemeProvider enableSystem={false} defaultTheme="light" themeCookie={{ name: "site-theme" }}> <SiteShell themeCookie={{ name: "site-theme" }} {...shell} /> </SiteThemeProvider> // Wrong too: themeCookie on a shell inside a plain next-themes provider <ThemeProvider attribute="class" enableSystem={false} defaultTheme="light"> <SiteShell themeCookie={{ name: "site-theme" }} {...shell} /> </ThemeProvider>
  1. Another app of the site, which allows the system theme, writes site-theme=system.
  2. The outer provider would ignore system (a SiteThemeProvider seed checks it against its own settings). The shell's seed accepts it and stores system in localStorage.
  3. The outer provider then reads system, a theme it does not know. <html> gets the class system, neither light nor dark, and the theme control selects System.
  4. The stored value stays, so every later visit paints the same broken theme until the visitor picks another one. With themeCookie on both, each theme change also writes the cookie twice.

Do this instead: keep themeCookie, enableSystem, storageKey and themes together on the outer provider, and give the shell none. If the outer provider is a plain next-themes ThemeProvider, replace it with SiteThemeProvider: it takes every ThemeProvider prop. Then set themeCookie there.

// Right: one themeCookie, on the outermost provider <SiteThemeProvider enableSystem={false} defaultTheme="light" themeCookie={{ name: "site-theme" }}> <SiteShell {...shell} /> </SiteThemeProvider>

Only when the shell is the only theme provider of the page (no SiteThemeProvider and no next-themes ThemeProvider around it) does themeCookie go on the shell.

Link events and analytics

Every link the header and the footer draw carries data-shell-slot: bar, menu, cta, switcher or footer. Mount ShellLinkEvents once, in a "use client" file, to get each click with its anchor and slot:

"use client"; import { ShellLinkEvents } from "@vllnt/ui/site-frame"; export function AcmeLinkTracking() { return ( <ShellLinkEvents onLinkClick={({ event, link, slot }) => { report("shell_link", { slot, href: link.href, newTab: event.metaKey || event.ctrlKey }); }} /> ); }
  • It adds one click listener on the document and renders nothing. Middle-clicks and right-clicks are not reported, and a stopPropagation() between the link and the document hides the click.
  • data on a nav item, the cta, the locale link, a network row or a footer link adds your own data-* attributes, e.g. { "data-to": "pricing" }. Any key that does not start with data- is dropped, and data-shell-slot cannot be replaced.
  • A page with no React can select on a[data-shell-slot] in its own script.

Languages: hrefLang and mark

  • locale on the header is the link to the same page in the other language: { ariaLabel, href, hrefLang, label, name }. label shows in the bar (FR), name in the menu (Français).
  • hrefLang on a nav item, a footer link or a network row sets hreflang on the anchor, so browsers and search engines know the language of the target page.
  • mark adds short muted text inside the link, e.g. EN for a page in another language. It is part of the link's name (About EN), so an end-to-end check that matches the exact name must include it.
items={[{ href: "https://example.com/en/about", hrefLang: "en", label: "About", mark: "EN" }]} locale={{ ariaLabel: "FR, read this page in French", href: "/fr/guides", hrefLang: "fr", label: "FR", name: "Français" }}

Props

Every prop, field and default is on the docs page of each part in Storybook, under Layout: SiteShell, SiteShellStatic, SiteFrame (with SiteThemeProvider, the cookie fields, the page with no React and ShellLinkEvents), SiteHeader (labels, locale, network rows, data and slots), SiteHeaderStatic, SiteFooter and SiteMain. The same text is in the TSDoc of the exported props types, such as SiteShellProps, SiteHeaderProps and ThemeCookieOptions. SiteShell, SiteShellStatic, SiteFrame and SiteMain also have registry pages with their source.

Ask your agent about this page

Copy a prompt into your coding agent. It points the agent at this page, so the answer comes from the same content you are reading.

  • Explain

    Summarise this page in a few lines.

    Show prompt

    Fetch https://ui.vllnt.com/docs/site-shell with the request header `Accept: text/markdown` to read this page as markdown. If you cannot set the header, fetch the page as is. Summarise it in a few lines. Use only that page, and say when something is not covered there.

  • In my repo

    Find where this page applies to your project. Read-only, no edits.

    Show prompt

    Read-only task: do not edit, create or delete files, and do not run install or `shadcn add` commands. Fetch https://ui.vllnt.com/docs/site-shell with the request header `Accept: text/markdown` to read this page as markdown. If you cannot set the header, fetch the page as is. Then find where this page applies to the current project, list the files involved, and sketch the smallest change. If nothing fits, say so.

Theme