Web · Components
Kbd
A keyboard key or shortcut.
3 exports
Live example
Preview
Press Control+Shift+P to open commands.
Code
Events
- Events appear here when you interact with the preview.
Key sequence and hand-written key
Go to dashboard: G, DSend: Control+EnterEsc
Import
A keyboard key or shortcut. The shortcut is given with keys and written per the user's operating system: "⌘K" on macOS/iOS, "Ctrl+K" on Windows/Linux. Uses the same notation as menu and CommandPalette shortcuts.
- Screen readers read key names, not symbols ("Meta+K").
- On the server and on first render it is written in the Windows format, then updated for the real system; there is no hydration mismatch.
- To hide it on touch devices use
className="pointer-coarse:hidden".
Examples
KbdVariant
typeLook of the key box.
outline: bordered with a thick bottom edge; looks like a real key.soft: borderless, pale background; plain in menus and tooltips.ghost: text only; inside buttons.
KbdProps
interfaceProps of the Kbd component.
Extends: Omit<ComponentProps<"kbd">, "children">
| Name | Type | Default | Description |
|---|---|---|---|
keys? | string | Shortcut to show: "Mod+K", "Mod+Shift+P", "Alt+Enter", "Esc". Mod is written as ⌘ on macOS/iOS and Ctrl on other systems. For a key sequence (e.g. G then D) separate with a space: "G D". If omitted, children is shown as is. | |
children? | ReactNode | Manually written content instead of keys (e.g. "Enter"). | |
split? | boolean | false | Show each key in a separate box? If false, the whole shortcut is in one box (e.g. "⇧⌘P" or "Ctrl+Shift+P"). |
variant? | KbdVariant | CustomVariant<"kbd"> | "outline" | Appearance: built-in (KbdVariant) or a custom appearance added with defineAppearance. If omitted, UIProvider appearance.defaults.kbd.variant. |
size? | "sm" | "md" | "md" | Size. |