Kbd
A keyboard key indicator for documenting shortcuts. Renders a native <kbd>; the default variant is a flat gray chip (no border, no shadow) that re-themes everywhere. Compose combos by placing several side by side.
Installation#
Usage#
import { Kbd } from "@/components/ui/kbd"
export function Example() {
return <Kbd>Esc</Kbd>
}Variants#
default is a flat gray chip (no border, no shadow) whose translucent fill stays visible on any surface, a highlighted menu row included. soft is an alias of that same chip, outline is a hairline cap over a transparent fill for a key that should read lighter, solid inverts for high-contrast callouts, and ghost drops the cap entirely: just the muted glyph, for ⌘K hints inside a button or input where a raised key would read as a second control.
Sizes#
Combinations#
Kbd is a single key by design. Build a shortcut by placing several side by side in an inline-flex row, and each key keeps its own cap.
Inline#
Drop a key straight into running text. At size="sm" the gray chip sits inside the line height without pushing the lines apart.
API reference#
Kbd
One key. Renders a native <kbd> and forwards all its props. Accepts className, merged last.
| Prop | Type | Default | Description |
|---|---|---|---|
| variant | "default" | "soft" | "outline" | "solid" | "ghost" | "default" | default is the flat gray chip; soft is an alias of it. outline is a hairline cap, solid an inverted one, ghost just the muted glyph. |
| size | "sm" | "md" | "lg" | "md" | Cap height: 20, 24 or 28px. |
| asChild | boolean | false | Renders the child element as the key (Radix Slot) instead of a <kbd>. |