Kbd
Key caps for shortcuts that show the right symbols on every platform, read them out properly and press down with the real keys.
- Data display components
- 2 parts
- 8 examples
- vs shadcn/ui
@base-ui/reactclass-variance-authority
See it in a real product: Agent Todos, Artifact, Chat Sidebar, and 17 more
View blockPress Command K to search, or hold Shift and watch the keys.
pnpm dlx shadcn@latest add https://hextaui.com/r/kbd.jsonAdds the component, the HextaUI theme tokens and any HextaUI components it depends on.
Add the theme tokens to your global CSS, if you haven’t yet.
Install the dependencies.
pnpm add @base-ui/react class-variance-authority cnCopy and paste the following code into your project.
components/ui/kbd.tsx lib/hotkey.ts Update the import paths to match your project setup.
Write shortcuts once with keys and they show as ⌘K on a Mac and Ctrl K on Windows and Linux. Or pass any content as children for full control.
keycap has a hairline edge and a 1px lip so it reads as a physical key. flat is a quiet fill for dense places like menus.
sm sits in small text, default next to body text and lg in headings or on its own.
<KbdGroup /> splits a combo into one cap per key. A space starts a sequence, joined by separator. <Kbd /> with keys keeps the whole combo in one cap.
With listen, a cap presses down while its real key is held. It only watches, so it never blocks, delays or changes what you type. Letters match by physical key, so Option and Shift don't confuse them.
Inside a button, the cap takes its colors from the button's text, so it fits every variant.
Put icons in a cap for actions without a key name, and give them a visually hidden label.
Shortcuts stay in left-to-right order inside right-to-left text, the way they're printed on the keyboard.
- Symbols like ⌘ and ⇧ are hidden from screen readers and replaced with their names, so
keys="mod+shift+p"is read as "Command Shift P". - Caps render as
<kbd>, and a group nests them in another<kbd>, which is how HTML marks a key combination. - Showing a shortcut doesn't bind it. Register the key handler yourself.
- The press effect is decoration, with a color change in place of movement when reduced motion is on. Before hydration, every platform sees the Apple symbols.
Both parts render a <kbd> and accept render and its attributes.
| Prop | Type | Default |
|---|---|---|
keysKeys joined with +, like "mod+shift+p". mod is ⌘ on Apple devices and Ctrl elsewhere. Names such as alt, enter, escape, up and space become symbols or short words, and get a spoken name for screen readers. | string | – |
variantInherited from KbdGroup when unset. | "keycap" | "flat" | "keycap" |
sizeInherited from KbdGroup when unset. | "sm" | "default" | "lg" | "default" |
listenPress the cap while its real key is held. Works with keys or a plain key name as children. | boolean | false |
render | ReactElement | (props, state) => ReactElement | <kbd> |
| Attribute | Description |
|---|---|
data-slot="kbd" | Target caps in CSS. |
data-variant | The current variant. |
data-size | The current size. |
data-pressed | Present while the real key is held. |
| Prop | Type | Default |
|---|---|---|
keysKeys joined with +, like "mod+shift+p". mod is ⌘ on Apple devices and Ctrl elsewhere. Names such as alt, enter, escape, up and space become symbols or short words, and get a spoken name for screen readers. Spaces separate the steps of a sequence. | string | – |
separatorShown between the steps of a sequence. | ReactNode | "then" |
variantPassed to every cap inside. | "keycap" | "flat" | – |
sizePassed to every cap inside. | "sm" | "default" | "lg" | – |
listenPassed to every cap inside. | boolean | – |
render | ReactElement | (props, state) => ReactElement | <kbd> |
| Attribute | Description |
|---|---|
data-slot="kbd-group" | Target groups in CSS. |
data-slot="kbd-separator" | The text between sequence steps. |
- HotkeyParse, label, announce and match keyboard shortcuts, with ⌘ on Apple platforms and Ctrl everywhere else.
- useHeldKeysThe keys someone is holding down right now, shared by every subscriber through a single set of window listeners.
- AvatarUser photos with an initials fallback, status badges and stacked groups that collapse into a count.
- BadgeStatus labels with colored dots, removable tags that slide closed and counts that roll to their new value.
- CardA surface for grouping content, with three variants, edge-to-edge media, concentric radii and whole-card links.
- ChartRecharts charts with themed colors, a tooltip and legend that read labels from one config, and keyboard navigation with a visible focus ring.
Used in Pro blocks
Blocks that build on Kbd.
Every block comes with HextaUI Pro, and Prompt Input is free.