Skip to content
Haze UI

Tabs

Tab list switching panels horizontally or vertically in pill or underline style, with sizing, badges, and in-page link fallback.

pnpm dlx shadcn@latest add @haze/tabs
Open preview in a new tab
Livesmall script

When to use

  • Two to six views of the same object, such as overview, activity and settings
  • Monthly and yearly variants of the same pricing content
  • Vertical sub-navigation inside settings panes or documentation views

When not to use

  • Moving between different routes without shared controls; use segmented-control or nav links
  • Content people need to compare side by side
  • More than about eight tabs, or labels that must all be visible at once; use orientation="vertical", select or an accordion (scrollable handles a few extra tabs on a narrow row)

Installation

Add the Haze registry to components.json once, then install Tabs with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.

pnpm dlx shadcn@latest add @haze/tabs
First time? Registry and theme setup

1. Add to components.json:

{
  "registries": {
    "@haze": "http://localhost:4329/r/{name}.json"
  }
}

2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";

API reference

PropTypeDefaultDescription
tabs*{ id: string; label: string; badge?: string | number; disabled?: boolean }[]–One entry per tab. id matches its slot panel element id.
label*string–Accessible name for the tab list.
variant"pill" | "line" | "underline""pill"pill slides a raised key on a sunken track; line/underline slides an indicator bar along an edge rule.
size"sm" | "md" | "lg""md"Controls tab height and horizontal padding.
orientation"horizontal" | "vertical""horizontal"Stacks tabs beside panels on wide screens with vertical arrow navigation.
scrollablebooleanfalseHorizontal only. Keeps one row and lets a long tab list scroll sideways, with edge fades on the cut-off sides and, with script, previous / next buttons shown only where more tabs are hidden. The selected tab is scrolled into view on load and on change.
scrollPreviousLabelstring"Scroll tabs left"Accessible name of the scroll-left button (scrollable only).
scrollNextLabelstring"Scroll tabs right"Accessible name of the scroll-right button (scrollable only).
classstring–Extra classes on the wrapper.
default slot*slot–One direct child panel per tab in the same order, each carrying the matching id.

Keyboard interactions

LeftRight (or UpDown when vertical)
Select the previous or next enabled tab, wrapping at ends
HomeEnd
Select the first or last enabled tab
SpaceEnter
Select the focused tab
Tab
Move from the selected tab into its panel

Accessibility

  • The script adds tablist, tab, tabpanel roles, aria-orientation when vertical, aria-selected, aria-controls, and roving tabindex while skipping disabled tabs.
  • Without scripts the tab list stays a navigation landmark of in-page links, and CSS reveals the matching :target panel.
  • A link or the Back button that points at a panel or any element inside one selects that tab automatically.
  • With scrollable, the list keeps its native scrollbar as the visible cue and adds edge fades; the optional scroll buttons are real, labelled buttons that appear only when tabs are cut off on that side. Arrow keys still select and reveal tabs, so the buttons are a pointer and touch aid.
  • The indicator updates --tab-x, --tab-y, --tab-w, and --tab-h via ResizeObserver without gliding on initial load.

Notes for AI

Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.

  • Install and use

    Install the Haze UI component "Tabs" with `npx shadcn@latest add @haze/tabs`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "http://localhost:4329/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import Tabs from "@/components/haze/ui/tabs.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: http://localhost:4329/ui/tabs.md

  • Customize with real content

    Adapt the Haze tabs ui for our product. Replace the demo values of these props with our real content: tabs, label, variant, size, orientation, scrollable, scrollPreviousLabel, scrollNextLabel, class, default slot. Keep the layout, the heading level rules and these accessibility details: The script adds tablist, tab, tabpanel roles, aria-orientation when vertical, aria-selected, aria-controls, and roving tabindex while skipping disabled tabs. Without scripts the tab list stays a navigation landmark of in-page links, and CSS reveals the matching :target panel. A link or the Back button that points at a panel or any element inside one selects that tab automatically. With scrollable, the list keeps its native scrollbar as the visible cue and adds edge fades; the optional scroll buttons are real, labelled buttons that appear only when tabs are cut off on that side. Arrow keys still select and reveal tabs, so the buttons are a pointer and touch aid. The indicator updates --tab-x, --tab-y, --tab-w, and --tab-h via ResizeObserver without gliding on initial load. Do not add raw color classes; use the Haze tokens.

  • Choose the right block

    Before using tabs, check it fits: use it when two to six views of the same object, such as overview, activity and settings; monthly and yearly variants of the same pricing content; vertical sub-navigation inside settings panes or documentation views. Avoid it when moving between different routes without shared controls; use segmented-control or nav links; content people need to compare side by side; more than about eight tabs, or labels that must all be visible at once; use orientation="vertical", select or an accordion (scrollable handles a few extra tabs on a narrow row). Alternatives: @haze/segmented-control, @haze/accordion, @haze/select.

Dependencies

  • npm: @lucide/astro
  • @haze/utils
  • @haze/theme (one-time setup)

Source · Original Haze UI work.

Catalog

↑↓ moveEnter openEsc close

Keyboard shortcuts

CtrlK
Command palette
/
Focus search
←↑→↓
Move between cards
jk
Next / previous card
ci
Copy code / install command (detail page)
[]
Previous / next entry
?
This help
Esc
Close dialog