Kbd
Key caps for shortcuts that show the right symbols on every platform, read them out properly and press down with the real keys.
Press 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.
Variants
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.
Sizes
sm sits in small text, default next to body text and lg in headings or on its own.
Shortcuts
<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.
- Command palette
- CommandK
- Move line up
- OptionUp arrow
- Close
- Escape
- Go to dashboard
- GthenD
- Save, as one cap
- Command S
Live keys
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.
In a button
Inside a button, the cap takes its colors from the button's text, so it fits every variant.
Icons and actions
Put icons in a cap for actions without a key name, and give them a visually hidden label.
ShiftClickto select a range
Backspaceto go back
Right to left
Shortcuts stay in left-to-right order inside right-to-left text, the way they're printed on the keyboard.
اضغطShiftCommandPلفتح لوحة الأوامر، أو Escape للإغلاق
- 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. |