Navigation · Material 3: Toolbars
Toolbar
Frequent actions for the current page. Floating on its own pill, or docked along an edge. One tab stop; arrow keys move inside.
Examples and variants
Floating
Text formatting tools.
function ToolbarFloating() {
return (
<Toolbar aria-label="Formatting">
<ToolbarGroup>
<ToolbarButton render={<Button size="icon" variant="ghost" aria-label="Bold" />}>
<BoldIcon />
</ToolbarButton>
<ToolbarButton render={<Button size="icon" variant="ghost" aria-label="Italic" />}>
<ItalicIcon />
</ToolbarButton>
</ToolbarGroup>
<ToolbarSeparator />
<ToolbarButton render={<Button size="icon" variant="ghost" aria-label="Share" />}>
<ShareIcon />
</ToolbarButton>
</Toolbar>
)
}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.
npx shadcn@latest add https://isotopi.com/r/minimal.json
npx shadcn@latest add https://isotopi.com/r/toolbar.jsonBy hand
No CLI needed. Add the foundation once (see Getting started), then follow these steps. They include every component this one builds on.
Install the packages it uses.
Terminalnpm install @base-ui/react cnCopy this file to the same paths in your project. Imports use the
@/alias for your project root.components/ui/toolbar.tsxtoolbar
components/ui/toolbar.tsx"use client" import * as React from "react" import { Toolbar as ToolbarPrimitive } from "@base-ui/react/toolbar" import { cn } from "cn" /* Toolbar: frequent actions for the current page. variant="floating" sits on its own raised pill; "docked" spans its container's edge. Arrow keys move between items (one tab stop for the whole toolbar). */ function Toolbar({ className, variant = "floating", ...props }: ToolbarPrimitive.Root.Props & { variant?: "floating" | "docked" }) { return ( <ToolbarPrimitive.Root data-slot="toolbar" data-variant={variant} className={cn( "flex items-center gap-1 p-(--toolbar-padding)", variant === "floating" ? "w-fit rounded-(--toolbar-corner) bg-(--toolbar-container) shadow-(--toolbar-elevation)" : "w-full bg-(--surface-container-low) px-(--space-3)", className )} {...props} /> ) } function ToolbarButton(props: ToolbarPrimitive.Button.Props) { return <ToolbarPrimitive.Button data-slot="toolbar-button" {...props} /> } function ToolbarGroup({ className, ...props }: ToolbarPrimitive.Group.Props) { return <ToolbarPrimitive.Group data-slot="toolbar-group" className={cn("flex items-center gap-1", className)} {...props} /> } function ToolbarSeparator({ className, ...props }: ToolbarPrimitive.Separator.Props) { return ( <ToolbarPrimitive.Separator data-slot="toolbar-separator" className={cn("mx-1 h-(--size-icon-lg) w-(--divider-thickness) bg-(--divider-color)", className)} {...props} /> ) } export { Toolbar, ToolbarButton, ToolbarGroup, ToolbarSeparator }
Imports
What the examples on this page import:
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
- 1Container · --toolbar-container, --toolbar-corner, --toolbar-padding, --toolbar-elevation.
- 2Buttons · Icon Buttons rendered through ToolbarButton.
- 3Separator · A faint tint between groups.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
variant | "floating" | "docked" | "floating" | Placement. |
orientation | "horizontal" | "vertical" | "horizontal" | Direction. |
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.
| Token | Points to | Light | Dark |
|---|---|---|---|
--toolbar-container | var(--surface-container-raised) | oklch(1 0 0) | oklch(0.22 0 0) |
--toolbar-corner | var(--shape-full) | 999px | same |
--toolbar-padding | var(--space-1) | 4px | same |
--toolbar-elevation | var(--elevation-2) | 0 1px 1px -0.5px oklch(0.22 0.01 260 / 6%), 0 3px 3px -1.5px oklch(0.22 0.01 260 / 6%), 0 6px 6px -3px oklch(0.22 0.01 260 / 6%), 0 12px 12px -6px oklch(0.22 0.01 260 / 6%), 0 24px 24px -12px oklch(0.22 0.01 260 / 6%) | 0 4px 12px oklch(0 0 0 / 40%), 0 12px 28px oklch(0 0 0 / 35%) |
Motion
| Trigger | What happens | Tokens |
|---|---|---|
| Press | Buttons squash like any Button. | --button-press-scale |
Calm keeps the motion without overshoot. Still (and reduced motion) keeps a designed frame with no movement.
Accessibility
- role=toolbar with a label.
- Arrow keys move; Tab leaves the toolbar.
Usage
Do
- Group actions for the page or selection.
Don’t
- Don't put navigation in a toolbar.
Code
"use client"
import * as React from "react"
import { Toolbar as ToolbarPrimitive } from "@base-ui/react/toolbar"
import { cn } from "cn"
/*
Toolbar: frequent actions for the current page. variant="floating" sits on
its own raised pill; "docked" spans its container's edge. Arrow keys move
between items (one tab stop for the whole toolbar).
*/
function Toolbar({
className,
variant = "floating",
...props
}: ToolbarPrimitive.Root.Props & { variant?: "floating" | "docked" }) {
return (
<ToolbarPrimitive.Root
data-slot="toolbar"
data-variant={variant}
className={cn(
"flex items-center gap-1 p-(--toolbar-padding)",
variant === "floating"
? "w-fit rounded-(--toolbar-corner) bg-(--toolbar-container) shadow-(--toolbar-elevation)"
: "w-full bg-(--surface-container-low) px-(--space-3)",
className
)}
{...props}
/>
)
}
function ToolbarButton(props: ToolbarPrimitive.Button.Props) {
return <ToolbarPrimitive.Button data-slot="toolbar-button" {...props} />
}
function ToolbarGroup({ className, ...props }: ToolbarPrimitive.Group.Props) {
return <ToolbarPrimitive.Group data-slot="toolbar-group" className={cn("flex items-center gap-1", className)} {...props} />
}
function ToolbarSeparator({ className, ...props }: ToolbarPrimitive.Separator.Props) {
return (
<ToolbarPrimitive.Separator
data-slot="toolbar-separator"
className={cn("mx-1 h-(--size-icon-lg) w-(--divider-thickness) bg-(--divider-color)", className)}
{...props}
/>
)
}
export { Toolbar, ToolbarButton, ToolbarGroup, ToolbarSeparator }