Kbd
Display keyboard keys and shortcuts with compact, consistent styling.
Preview
Kbd presents a key or key combination. It does not register shortcuts or handle keyboard events. The examples on this page display hints only.
Installation
pnpm dlx shadcn@latest add http://127.0.0.1:3017/r/kbd.jsonInstalls Kbd and KbdGroup in one source file. No additional package dependencies are required. Uses your existing cn utility and semantic theme tokens. Input Group, Button, and Tooltip are separate components used in the examples. See the registry guide for local endpoint details.
Usage
import { Kbd, KbdGroup } from '@/components/ui/kbd';
<Kbd>Enter</Kbd>
<KbdGroup aria-label="Command plus K">
<Kbd>⌘</Kbd>
<Kbd>K</Kbd>
</KbdGroup>Both components render native kbd elements and work in Server Components without a client directive.
Composition
Use Kbd by itself for one key, or group keys that belong to a combination:
KbdGroup (optional)
├── Kbd
├── Separator text (optional, such as +)
└── KbdKbdGroup owns the 4px gap between keys. Kbd owns the key surface, padding, and text styling. Nested native kbd elements describe the individual keys within a larger keyboard input. Keep Kbd inside the action or helper text it explains; it is not an interactive control.
With Input Group
<InputGroup>
<InputGroupInput aria-label="Search projects" placeholder="Search projects…" />
<InputGroupAddon align="inline-end">
<KbdGroup aria-label="Control plus K">
<Kbd>Ctrl</Kbd>
<Kbd>K</Kbd>
</KbdGroup>
</InputGroupAddon>
</InputGroup>Import InputGroup, InputGroupInput, and InputGroupAddon from the Input Group module. Only show an active shortcut in a product when the application actually implements it.
With Tooltip
Kbd automatically adjusts its foreground and surface inside TooltipContent. The trigger keeps its own accessible name; the shortcut is supplementary help.
Appearance
| Setting | Default |
|---|---|
| Height / minimum width | 20px |
| Horizontal padding | 4px |
| Corner radius | Small control token, 3px fallback |
| Typography | Sans, 12px / 16px, medium |
| Group spacing | 4px |
| Surface / text | Muted / muted foreground |
| Icons | 14px, stroke width 1.75 |
Long key names such as Enter and Backspace grow to fit. Kbd has no default shadow and does not receive pointer events.
Accessibility
- Prefer recognizable key names. Give symbol combinations a readable label, such as
aria-label="Command plus Shift plus P"on KbdGroup. - Hide decorative plus signs from assistive technology when a group label already describes the combination.
- Do not add a tab stop or click handler to a keycap. Put actions on a real button or link.
- Choose shortcut notation for the platform supported by your application. These examples do not detect the user's operating system.
API
Kbd and KbdGroup accept native kbd props, including children, className, ref, and accessibility attributes. Neither component manages state or installs keyboard listeners.
Based on shadcn Kbd.