# Page header

> The top of every app page: breadcrumbs, title, status, actions and tabs. As you scroll, the title glides up and shrinks into a sticky bar.

Most page headers either scroll away, taking the actions with them, or stay pinned at full height and eat a third of a laptop screen. This one condenses with the scroll itself, not with a toggle. The breadcrumbs scroll off while the parent page turns into a back link, the large title glides up and shrinks into a slim sticky bar, the status badge follows the title's end, the actions ride down into the bar and the tabs stay pinned underneath. Scroll back up and it unfolds the same way. Moving between pages keeps the crumbs the two trails share and slides the new one in from the right; going up, the crumbs you leave slide out the same way, and the title morphs letter by letter. Actions are async buttons that say what happened in place (Creating, Created). When the header is narrow, the trail becomes a back link and the secondary actions fold into a menu.

## Install

```bash
npx shadcn@latest add @hairline/page-header
```

Needs React 19, Tailwind CSS v4 and shadcn/ui theme variables (any style, light and dark). Icons from lucide-react.

- npm: `lucide-react`
- Hairline UI components it needs (the CLI installs them too): `dropdown-menu`, `number-roll`, `status-button`, `text-morph`
- Docs and live preview: https://hairlineui.com/ui/page-header
- Registry item (source): https://hairlineui.com/r/page-header.json

## Usage

```tsx
import { Plus } from "lucide-react";
import { PageHeader } from "@/components/page-header";

<PageHeader
  breadcrumbs={[{ label: "Projects", href: "/projects" }]}
  title="Website relaunch"
  description="New pricing page and one signup field, before the December launch."
  actions={[
    { id: "new", label: "New issue", icon: <Plus className="size-4" />, primary: true, onAction: () => createIssue() },
  ]}
  tabs={[{ id: "overview", label: "Overview" }, { id: "issues", label: "Issues", count: 12 }]}
/>
```

## On a Next.js project page

The trail and tabs are links, so the header works with the router. Actions call server actions and the buttons report back on their own. Put the header first inside the element that scrolls (here, the page's main) so it can condense.

```tsx
// app/projects/[id]/layout.tsx
import { getProject } from "@/lib/projects";
import { ProjectHeader } from "./project-header";

export default async function ProjectLayout({ params, children }: { params: Promise<{ id: string }>; children: React.ReactNode }) {
  const { id } = await params;
  const project = await getProject(id);
  return (
    <main className="h-dvh overflow-y-auto">
      <ProjectHeader project={project} />
      {children}
    </main>
  );
}

// app/projects/[id]/project-header.tsx
"use client";
import Link from "next/link";
import { useSelectedLayoutSegment } from "next/navigation";
import { Plus } from "lucide-react";
import { PageHeader } from "@/components/page-header";
import { archiveProject, createIssue } from "./actions";

export function ProjectHeader({ project }: { project: { id: string; name: string; summary: string; open: number } }) {
  const segment = useSelectedLayoutSegment() ?? "overview";
  const base = `/projects/${project.id}`;
  return (
    <PageHeader
      linkAs={Link}
      breadcrumbs={[{ label: "Projects", href: "/projects" }]}
      title={project.name}
      description={project.summary}
      actions={[
        { id: "archive", label: "Archive", onAction: () => archiveProject(project.id), successLabel: "Archived" },
        { id: "new", label: "New issue", icon: <Plus className="size-4" />, primary: true, onAction: () => createIssue(project.id), pendingLabel: "Creating", successLabel: "Created" },
      ]}
      tab={segment}
      tabs={[
        { id: "overview", label: "Overview", href: base },
        { id: "issues", label: "Issues", count: project.open, href: `${base}/issues` },
        { id: "settings", label: "Settings", href: `${base}/settings` },
      ]}
    />
  );
}
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `title` | `string` | – | The page's name. Changes morph letter by letter. |
| `description` | `string` | – | One or two lines under the title. Fades as the header condenses. |
| `breadcrumbs` | `{ label, href?, onClick? }[]` | – | The trail to this page, without the page itself. The last crumb is the parent: it becomes the back link. |
| `badge` | `ReactNode` | – | Beside the title, e.g. a status pill. It follows the title into the bar. |
| `meta` | `ReactNode` | – | A line under the description: owners, a due date, counts. |
| `actions` | `PageAction[]` | – | { id, label, icon?, primary?, destructive?, onAction?, pendingLabel?, successLabel?, errorLabel? }. Return a promise from onAction to get pending, done and failed states. |
| `tabs` | `{ id, label, count?, href? }[]` | – | The page's sections, pinned under the bar. |
| `tab / defaultTab / onTabChange` | `string` | – | The chosen tab. |
| `condense` | `boolean` | `true` | Condense into a sticky bar on scroll. |
| `scrollContainer` | `RefObject<HTMLElement>` | – | The element that scrolls. Defaults to the nearest scrolling ancestor, or the window. |
| `linkAs` | `ElementType` | `"a"` | Crumbs and tabs with href render as this, e.g. Next.js Link. |

## States

- **full**: Breadcrumbs (13px), the title (26px, 22px when narrow) with its badge, the actions on the right, the description, a meta line and the tabs. Above the tabs nothing is pinned yet.
- **condensing**: Scrolling moves every part in step with the scroll, with no timing of its own. The trail fades out over the first 40% as it scrolls off, the description and meta fade over the first 55%, the title moves up and scales down to 15px about its left edge, the badge keeps to the title's end, and the actions travel down into the bar. Over the last 40% the parent page's back link fades in from 6px to the left, and the title slides over to make room for it.
- **condensed**: A 52px sticky bar: back link, title, badge and actions, with the tabs pinned under it. Without tabs a 1px hairline fades in under the bar. Scroll back to the top and it unfolds the same way.
- **navigate**: When the trail changes, crumbs the old and new trails share stay. New ones slide in 8px from the right (380ms, 70ms apart) and leaving ones close their width as they slide 10px right and blur out (360ms). The title morphs letter by letter and the description rises in through a 4px blur.
- **action**: An action whose onAction returns a promise shows its pending label with a spinner, then its success label with a drawn check, and returns to idle after 1.8s. If the promise rejects, the button shakes and says Try again.
- **narrow**: Below 576px of the header's own width, the trail is replaced by a back link to the parent, secondary actions fold into a ⋯ menu beside the primary one, and the tabs scroll sideways with faded edges.

## What it handles

A page header is either scrolled away with its actions or stays pinned at full height. This one condenses into a bar in step with the scroll, keeping the title, actions and tabs in reach.

- **Condenses as you scroll**: The title glides up and shrinks into a sticky bar in step with the scroll; the actions follow and the tabs stay pinned.
- **A trail that knows direction**: Going deeper, shared crumbs stay and the new one slides in; going up, the ones you leave slide out.
- **A back link where it fits**: The parent page becomes a back link in the condensed bar and on narrow widths, where the trail would not fit.
- **Actions that report back**: Return a promise and the button shows Creating, then Created or Try again, in its own place.
- **Narrow without breaking**: Below 576px of its own width, the trail becomes a back link and secondary actions fold into a menu.
- **Tabs with counts**: The underline is thrown to the new tab, counts roll, and the strip scrolls to keep the chosen tab in view.

## Replaces

a page header, breadcrumbs, sticky header on scroll, collapsing large title, header actions with loading states, overflow menu for actions, page tabs

## Where it fits

- **Project and issue pages**: The project name, its status, New issue and the sections as tabs.
- **Settings and admin pages**: Where you are in a deep trail, with Save or Invite in reach while you scroll.
- **Detail pages in dashboards**: A customer, an order or a deployment with its actions and sections.
- **Long lists**: Inboxes, tables and feeds where the header must stay small once you scroll.

## Notes

- The title is the page's h1. The trail is a nav labelled Breadcrumb; the tabs are a navigation of links or buttons with aria-current="page" on the chosen one, and ← → Home End move between them.
- The condensed back link only takes focus once it shows; it is named "Back to Projects". The secondary actions' menu is a real menu with arrow keys and Escape.
- Condensing is direct manipulation: geometry is measured once per resize, and each scrolled frame writes transforms and opacity to a handful of elements. Nothing re-renders while you scroll.
- Put the header first inside the element that scrolls. It sticks with a negative top equal to the height it gives up, so the page under it never jumps.
- Action results are shown in the button and announced through its label; errors shake the button and keep it pressable to retry.
- Reduced motion keeps the condense (it follows your scroll), and drops the trail's slides, the title morph and the underline throw.

License: MIT (https://hairlineui.com/license#components)
