Kbd
A keyboard key, as the element that actually means one.
Press ⇧N to jump to the next unread study, or Esc to return to the worklist.
Installation
npx shadcn@latest add https://qure-ui.qure.ai/r/kbd.jsonUsage
import { Kbd, KbdGroup } from '@/components/ui/kbd'<KbdGroup>
<Kbd>⌘</Kbd>
<Kbd>K</Kbd>
</KbdGroup><kbd> is one of the few elements that says something a <span> cannot: this is a key you
press. There is no behaviour to own and no Base UI primitive, only semantics and a look — which
is exactly why it is easy to skip and worth not skipping.
Chords and sequences
- Window / level
- W
- Zoom
- Z
- Pan
- P
- Invert greyscale
- ⇧I
- Sign report
- ⌘⏎
Write a combination as several Kbd elements inside a KbdGroup, not one string. ⌘⏎ in a
single element is announced as two unfamiliar symbols; <Kbd>⌘</Kbd><Kbd>⏎</Kbd> is announced as
two keys, which is what it is.
Nesting Kbd inside Kbd is also valid HTML and is what the spec suggests for a combination, but
the group is easier to style: it carries the spacing and keeps the caps from touching.
Variants
key draws a cap and is the default — use it when the key stands on its own in a sentence.
plain is bare glyphs, which is how Figma draws a menu shortcut.
In a menu
Reach for variant="plain" inside a menu row. A drawn cap fights the row's brand fill on hover,
and the shortcut is meant to be read as a hint rather than as a control. The <kbd> element still
earns its place: the row announces as a command with a key attached, not as a command with a stray
symbol after it.
Size
sm is the default and matches body text. md is for a shortcut sheet or a hero hint where the
key is the subject of the line rather than an aside.
Use the platform's own glyphs — ⌘ ⇧ ⌥ ⏎ ⌫ — rather than spelling out "Cmd" or "Shift". They
are what is printed on the keys, and macOS users match them by shape. If you support Windows,
branch on the platform rather than writing Ctrl/⌘, which is a key nobody has.
API Reference
Kbd
Renders a <kbd>.
| Prop | Type | Default | Description |
|---|---|---|---|
variant | "key" | "plain" | "key" | key draws a cap; plain is bare glyphs. |
size | "sm" | "md" | "sm" | sm matches body text. |
KbdGroup
Renders a <span>. Takes no props of its own beyond the usual span props.