Skip to content
Haze UI

Kbd

Monospace key cap built on the kbd element with a thick bottom edge; pass several keys to show a combination like Ctrl + K.

pnpm dlx shadcn@latest add @haze/kbd
Open preview in a new tab
Liveno JavaScript

When to use

  • Showing a shortcut hint beside a menu item or search field, such as Ctrl K
  • Documenting a key press inside help text or onboarding copy
  • Listing a table of shortcuts where each row has a key combination

When not to use

  • The text is a code snippet or command; use a code element instead
  • The key cap should be clickable; it is display only, use a button

Installation

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

pnpm dlx shadcn@latest add @haze/kbd
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
keysstring[][]Key labels. One key renders a single cap; several render one cap each inside an outer kbd.
size"sm" | "md""md"Cap size: sm (20 px) for tight rows and inputs, md (24 px) for body text and shortcut lists.
classstring–Extra classes on the outermost kbd.
default slotslot–Content for a single key when keys is empty, for example an icon.

Accessibility

  • Uses the semantic kbd element, so assistive tech announces the text as keyboard input.
  • A combination is one outer kbd wrapping one kbd per key, matching the HTML spec for key sequences.
  • Spell out symbol-only keys in the label (use "Esc" or "Shift", not an arrow glyph alone) so screen readers read them.

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 "Kbd" with `npx shadcn@latest add @haze/kbd`. 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 Kbd from "@/components/haze/ui/kbd.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/kbd.md

  • Customize with real content

    Adapt the Haze kbd ui for our product. Replace the demo values of these props with our real content: keys, size, class, default slot. Keep the layout, the heading level rules and these accessibility details: Uses the semantic kbd element, so assistive tech announces the text as keyboard input. A combination is one outer kbd wrapping one kbd per key, matching the HTML spec for key sequences. Spell out symbol-only keys in the label (use "Esc" or "Shift", not an arrow glyph alone) so screen readers read them. Do not add raw color classes; use the Haze tokens.

  • Choose the right block

    Before using kbd, check it fits: use it when showing a shortcut hint beside a menu item or search field, such as ctrl k; documenting a key press inside help text or onboarding copy; listing a table of shortcuts where each row has a key combination. Avoid it when the text is a code snippet or command; use a code element instead; the key cap should be clickable; it is display only, use a button. Alternatives: @haze/badge.

Dependencies

  • @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