Kbd prints a key the way a keyboard does: the text face at 14 px and weight 650 (never mono), a 2 px ink rule and a 2 px hard offset, the hit key in miniature. Pass keys for a combination; each key gets its own cap and the caps are joined by a plus sign.
Example#
Press CtrlK or / to search, and Escape to close.
Usage#
Use Kbd to name keys in instructions and menus: "Press / to search", the shortcut beside a menu item. It prints the text face (never mono) on a small key with a hard offset, the hit key in miniature.
- Combinations.
keys={["Ctrl", "K"]}prints a cap per key joined by plus signs. - Platforms. Write the key people will see; when it differs, name both: "Ctrl or ⌘".
Anatomy#
Press CtrlK or / to search, and Escape to close.
- Key
data-mk-part="key" - PlusJoins the keys of a combination.
.mk-kbd-plus
Volume#
Reading layer: identical at every volume.
Quiet
Press CtrlK or / to search, and Escape to close.
Studio
Press CtrlK or / to search, and Escape to close.
Press
Press CtrlK or / to search, and Escape to close.
Rave
Press CtrlK or / to search, and Escape to close.
Content#
- Use the key's printed name: "Enter", "Escape", "Tab"; single characters as they look: "/".
Do and don't#
Do
Press / to search.
Don't
Press the slash key on your keyboard to search.
Accessibility#
- A combination is nested
<kbd>elements (HTML's own pattern), so screen readers read each key; the plus signs are hidden. - Key names are words where words exist ("Escape", "Page Down"); symbols such as ⌘ sit beside a word in the text around them.
The colour pairs it prints, with their contrast on both papers:
| Text | Surface | Role | Bone | Night |
|---|---|---|---|---|
--mk-on-slab | --mk-slab | label | 16.49:1 · Lc 98.7, passes | 16.21:1 · Lc 95.1, passes |
--mk-on-slab | --mk-slab | body-ui | 16.49:1 · Lc 98.7, passes | 16.21:1 · Lc 95.1, passes |
--mk-on-slab | --mk-slab | long | 16.49:1 · Lc 98.7, passes | 16.21:1 · Lc 95.1, passes |
--mk-code-text | --mk-code-surface | code | 18.42:1 · Lc 105.1, passes | 15.02:1 · Lc 95.4, passes |
--mk-code-keyword | --mk-code-surface | code | 7.17:1 · Lc 82.5, passes | 12.45:1 · Lc 82.7, passes |
--mk-code-string | --mk-code-surface | code | 6.72:1 · Lc 82.6, passes | 12.40:1 · Lc 83.0, passes |
--mk-code-number | --mk-code-surface | code | 6.82:1 · Lc 82.6, passes | 12.40:1 · Lc 82.5, passes |
--mk-code-function | --mk-code-surface | code | 6.75:1 · Lc 82.7, passes | 12.42:1 · Lc 82.7, passes |
--mk-code-comment | --mk-code-surface | code | 6.60:1 · Lc 82.7, passes | 12.47:1 · Lc 82.8, passes |
--mk-code-punctuation | --mk-code-surface | code | 8.06:1 · Lc 87.9, passes | 15.02:1 · Lc 95.4, passes |
Props#
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | none | One key's name or symbol (e.g. "Escape", "⌘"). |
keys | readonly string[] | none | A combination, printed as one cap per key joined by "+" (e.g. `["Ctrl", "K"]`). |
Tokens#
System tokens (6)
Its own properties (3)
--mk-kbd-leading--mk-kbd-offset--mk-kbd-pad
Changelog#
Arrived in 0.9.0.
ComboboxandComboboxItem(a case- and accent-insensitive filter by default, groups, chips formultiple, "Searching…", an empty message, a live result count, andinlinefor a list printed in place),PopoverwithPopoverTrigger,PopoverContentandPopoverClose,Menuwith its eleven parts (shortcuts asKbdcaps, checkbox and radio items, group labels, separators, submenus), andToastProviderwithuseToast(a slab pill, one at a time with three waiting, 5.2 s with a drain bar that holds while the region is hovered, focused or the window is away).Breadcrumbs,Pagination(withpaginationRange),Count,ProgressBar(bar, segments, indeterminate),AvatarandAvatarGroup,Tick,EmptyState,Kbd,SkeletonandLoader. Read the whole entry