← Components

Navigation · Material 3: App bars

App bar

The top of a screen: navigation icon, title and actions. Medium and large put a big title under the row that can collapse on scroll.

Examples and variants

Small and medium

Leading, title, trailing.

Inbox

Project settings

Example
function AppBarSizes() {
  return (
    <div className="flex w-full max-w-md flex-col gap-4">
      <AppBar
        className="rounded-(--shape-lg) shadow-1"
        title="Inbox"
        leading={
          <Button size="icon" variant="ghost" aria-label="Open menu">
            <MenuIcon />
          </Button>
        }
        trailing={
          <Button size="icon" variant="ghost" aria-label="Search">
            <SearchIcon />
          </Button>
        }
      />
      <AppBar
        size="md"
        className="rounded-(--shape-lg) shadow-1"
        title="Project settings"
        leading={
          <Button size="icon" variant="ghost" aria-label="Back">
            <ArrowLeftIcon />
          </Button>
        }
      />
    </div>
  )
}

Spec drawing

Measured from the live component at default density. Each code maps to the token that sets it; change the token and the drawing follows.

Install

With the CLI

The shadcn CLI only delivers files: it copies our code from the Isotopi registry into your project and installs the packages it uses. Add the foundation once, then the component.

Terminal
npx shadcn@latest add https://isotopi.com/r/minimal.json
npx shadcn@latest add https://isotopi.com/r/app-bar.json

By hand

No CLI needed. Add the foundation once (see Getting started), then follow these steps. They include every component this one builds on.

  1. Install the packages it uses.

    Terminal
    npm install cn
  2. Copy this file to the same paths in your project. Imports use the @/ alias for your project root.

    • components/ui/app-bar.tsxapp-bar
      components/ui/app-bar.tsx
      "use client"
      
      import * as React from "react"
      import { cn } from "cn"
      
      /*
        App bar: the top of a screen. Leading slot (menu or back), title, trailing
        actions. size="sm" is one row; "md" and "lg" put a bigger title under the
        row, and with collapse the big title shrinks into the row as you scroll.
      */
      function AppBar({
        className,
        size = "sm",
        title,
        leading,
        trailing,
        collapse = false,
        ...props
      }: Omit<React.ComponentProps<"header">, "title"> & {
        size?: "sm" | "md" | "lg"
        title: React.ReactNode
        leading?: React.ReactNode
        trailing?: React.ReactNode
        /** md/lg: shrink the big title into the row after scrolling. */
        collapse?: boolean
      }) {
        const [scrolled, setScrolled] = React.useState(false)
        React.useEffect(() => {
          if (!collapse) return
          const onScroll = () => setScrolled(window.scrollY > 8)
          onScroll()
          window.addEventListener("scroll", onScroll, { passive: true })
          return () => window.removeEventListener("scroll", onScroll)
        }, [collapse])
        const big = size !== "sm" && !scrolled
        return (
          <header
            data-slot="app-bar"
            data-size={size}
            data-scrolled={scrolled || undefined}
            className={cn("app-bar flex flex-col bg-(--app-bar-container) px-(--app-bar-padding-x)", className)}
            {...props}
          >
            <div className="flex h-(--app-bar-height) items-center gap-inline-sm">
              {leading ? <div className="-ms-2 flex items-center">{leading}</div> : null}
              <div className={cn("app-bar-row-title min-w-0 flex-1 truncate text-title", big && "opacity-0")} aria-hidden={big || undefined}>
                {title}
              </div>
              {trailing ? <div className="-me-2 flex items-center gap-1">{trailing}</div> : null}
            </div>
            {size !== "sm" ? (
              <div
                className={cn(
                  "app-bar-large-title overflow-hidden",
                  size === "md" ? "text-[length:var(--type-headline-size)]" : "text-[length:var(--type-display-size)] leading-(--type-display-leading)",
                  "font-semibold tracking-(--type-headline-tracking)",
                  !big && "app-bar-large-hidden"
                )}
              >
                <h1 className="pb-4">{title}</h1>
              </div>
            ) : null}
          </header>
        )
      }
      
      export { AppBar }
      

Imports

What the examples on this page import:

Imports
import {
import { AppBar } from "@/components/ui/app-bar"
import { Badge } from "@/components/ui/badge"
import { Breadcrumb } from "@/components/ui/breadcrumb"
import { Button } from "@/components/ui/button"
import { DropdownMenuItem } from "@/components/ui/dropdown-menu"
import { Fab } from "@/components/ui/fab"
import { Navigation, NavigationItem } from "@/components/ui/navigation"
import { Pagination } from "@/components/ui/pagination"
import { SplitButton } from "@/components/ui/split-button"
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"
import { Toolbar, ToolbarButton, ToolbarGroup, ToolbarSeparator } from "@/components/ui/toolbar"

Anatomy

  1. 1Container · --app-bar-container, --app-bar-height, --app-bar-padding-x.
  2. 2Leading · Menu or back button.
  3. 3Title · Row title, or a large title under it (md, lg).
  4. 4Trailing · Up to 3 icon buttons.

Props

PropTypeDefaultDescription
size"sm" | "md" | "lg""sm"Title size.
title, leading, trailingReactNode—Slots.
collapseboolean—Large title shrinks into the row on scroll.

Tokens

Every visual spec is a component token in styles/tokens/components.css, pointing at a semantic token. Change a token to restyle the component; themes change the semantic layer.

TokenPoints toLightDark
--app-bar-heightvar(--space-16)64pxsame
--app-bar-containervar(--surface-container-lowest)oklch(1 0 0)oklch(0.14 0 0)
--app-bar-padding-xvar(--space-page-gutter)clamp(16px, 4vw, 48px)same

Motion

TriggerWhat happensTokens
Scroll (collapse)The large title folds up and the row title fades in.--duration-medium, --ease-sheet

Calm keeps the motion without overshoot. Still (and reduced motion) keeps a designed frame with no movement.

Accessibility

  • Use a header element; the large title is the page h1.
  • Icon buttons need labels.

Usage

Do

  • One app bar per screen.

Don’t

  • Don't put more than 3 trailing actions; move the rest to a Menu.

Code

components/ui/app-bar.tsx
"use client"

import * as React from "react"
import { cn } from "cn"

/*
  App bar: the top of a screen. Leading slot (menu or back), title, trailing
  actions. size="sm" is one row; "md" and "lg" put a bigger title under the
  row, and with collapse the big title shrinks into the row as you scroll.
*/
function AppBar({
  className,
  size = "sm",
  title,
  leading,
  trailing,
  collapse = false,
  ...props
}: Omit<React.ComponentProps<"header">, "title"> & {
  size?: "sm" | "md" | "lg"
  title: React.ReactNode
  leading?: React.ReactNode
  trailing?: React.ReactNode
  /** md/lg: shrink the big title into the row after scrolling. */
  collapse?: boolean
}) {
  const [scrolled, setScrolled] = React.useState(false)
  React.useEffect(() => {
    if (!collapse) return
    const onScroll = () => setScrolled(window.scrollY > 8)
    onScroll()
    window.addEventListener("scroll", onScroll, { passive: true })
    return () => window.removeEventListener("scroll", onScroll)
  }, [collapse])
  const big = size !== "sm" && !scrolled
  return (
    <header
      data-slot="app-bar"
      data-size={size}
      data-scrolled={scrolled || undefined}
      className={cn("app-bar flex flex-col bg-(--app-bar-container) px-(--app-bar-padding-x)", className)}
      {...props}
    >
      <div className="flex h-(--app-bar-height) items-center gap-inline-sm">
        {leading ? <div className="-ms-2 flex items-center">{leading}</div> : null}
        <div className={cn("app-bar-row-title min-w-0 flex-1 truncate text-title", big && "opacity-0")} aria-hidden={big || undefined}>
          {title}
        </div>
        {trailing ? <div className="-me-2 flex items-center gap-1">{trailing}</div> : null}
      </div>
      {size !== "sm" ? (
        <div
          className={cn(
            "app-bar-large-title overflow-hidden",
            size === "md" ? "text-[length:var(--type-headline-size)]" : "text-[length:var(--type-display-size)] leading-(--type-display-leading)",
            "font-semibold tracking-(--type-headline-tracking)",
            !big && "app-bar-large-hidden"
          )}
        >
          <h1 className="pb-4">{title}</h1>
        </div>
      ) : null}
    </header>
  )
}

export { AppBar }