# Kbd

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

- Kind: ui · Category: Data display · Interactivity: none
- Install: `npx shadcn@latest add @haze/kbd`
- File: `src/components/haze/ui/kbd.astro`
- npm dependencies: none
- Registry dependencies: @haze/utils
- Docs page: https://hazeui.com/ui/kbd

## Use 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 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
- [badge](https://hazeui.com/ui/badge.md)

## Props

| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| keys | `string[]` | [] | no | Key labels. One key renders a single cap; several render one cap each inside an outer kbd. |
| size | `"sm" \| "md"` | "md" | no | Cap size: sm (20 px) for tight rows and inputs, md (24 px) for body text and shortcut lists. |
| class | `string` |  | no | Extra classes on the outermost kbd. |
| default slot | `slot` |  | no | 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.

## Agent prompts

### 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": "https://hazeui.com/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: https://hazeui.com/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.

## Example requests that should lead here
- Add a Ctrl K hint on the right side of the search input

## Source

```astro
---
import { cn } from "../../../lib/haze/utils";

interface Props {
  /** Key labels. One key renders one cap; several render one cap each inside an outer kbd. */
  keys?: string[];
  /** Cap size: sm for tight rows, md for body text. */
  size?: "sm" | "md";
  class?: string;
}

const { keys = [], size = "md", class: className } = Astro.props;
const hasSlot = Astro.slots.has("default");
const sizes = {
  sm: "h-5 min-w-5 px-1.5 text-[0.6875rem]/none",
  md: "h-6 min-w-6 px-2 text-xs/none",
};
const cap = cn(
  "inline-flex items-center justify-center rounded-md border border-frame-foreground/14 border-b-2 border-b-frame-foreground/24 bg-muted font-mono font-medium tracking-tight text-foreground select-none whitespace-nowrap",
  sizes[size],
);
---

{
  keys.length > 1 ? (
    <kbd class={cn("inline-flex items-center gap-1 align-middle", className)}>
      {keys.map((key) => (
        <kbd class={cap}>{key}</kbd>
      ))}
    </kbd>
  ) : keys.length === 1 ? (
    <kbd class={cn(cap, "align-middle", className)}>{keys[0]}</kbd>
  ) : hasSlot ? (
    <kbd class={cn(cap, "align-middle", className)}><slot /></kbd>
  ) : null
}
```
