Kbd
PolymorphicKeyboard-key and shortcut indicator. Shares Button's variant × color system, tuned into a display key cap.
Kbd is a non-interactive <kbd> styled with the kit's (variant × color) system. The shape and palette axes are the exact set Button exposes, so a shortcut hint speaks the same accent language as the action it labels — but without hover or click behavior.
import { Kbd } from '@42-central/ui-react/kbd';
<Kbd>⌘</Kbd>
<Kbd>⌘K</Kbd>
<Kbd variant="light" color="brand">Enter</Kbd>
<Kbd hotkey="mod+k" /> {/* [⌘] [K] on a Mac, [Ctrl] [K] elsewhere */}Playground
Component
Dir
Presets
Props
Code
<Component variant="default" size="md">
⌘
</Component>Full prop browser
Variants
The five shape treatments are exactly the set Button uses. The default variant is default — the neutral, bordered key cap that reads as a physical key: a translucent fill that adapts to whatever surface it sits on, a hairline border, and a 1px shade along the bottom edge for the lip of a real key.
Code
<Kbd variant="default">⌘</Kbd>
<Kbd variant="filled">⌘</Kbd>
<Kbd variant="light">⌘</Kbd>
<Kbd variant="outline">⌘</Kbd>
<Kbd variant="subtle">⌘</Kbd>default is palette-independent — color is ignored for fill/text on this variant.
Colors
Any palette color pairs with any variant except default. Reach for a color when the key belongs to a colored action (a green confirm, a red destructive shortcut).
Code
<Kbd variant="light" color="green">↵</Kbd>
<Kbd variant="filled" color="red">⌫</Kbd>
<Kbd variant="outline" color="blue">Tab</Kbd>Sizes
Each size steps the type by one Tailwind step — sm 12px, md 14px, lg 16px — so pick the one that matches the text the key sits beside: sm inside a Button or a search field, md in body copy. Single-character keys stay square (a per-size min-w equal to the height); wider labels grow horizontally. An icon inside a key draws a 1.5px stroke at every size.
Code
<Kbd size="sm">⌘</Kbd>
<Kbd size="md">⌘</Kbd>
<Kbd size="lg">⌘</Kbd>In context
A Kbd slots cleanly into a Button to surface its shortcut. The button drives layout; the key cap stays neutral.
Code
<Button variant="outline" color="neutral" startSlot={<Plus />} endSlot={<Kbd size="sm">⌘N</Kbd>}>
New file
</Button>It keeps its own size in an input's slot too, beside the field's own icon: a search field shows its shortcut at the end.
Code
<Input
startSlot={<Search />}
endSlot={<Kbd hotkey="mod+k" size="sm" />}
placeholder="Search"
/>From a hotkey
hotkey takes the same string as useHotkey and draws it the way the visitor's platform does, one cap per key: "mod+k" is K on a Mac and Ctrl K elsewhere. Bind and label a shortcut from one string, and the hint can't drift from the key that works.
Code
<Kbd hotkey="mod+k" />
<Kbd hotkey="shift+mod+p" />
<Kbd hotkey="mod+enter" />
<Kbd hotkey="/" />The demo shows your own platform's caps. A key with an honest icon is drawn with the same icon on both platforms: Shift, Enter, Tab and the arrows. Apple's own symbols (⌘ ⌥ ⌃) are icons only on Apple; elsewhere Ctrl, Alt and Meta stay words, as do Esc and Space everywhere. Backspace is an icon only on Apple too: elsewhere ⌫ reads as the Left Arrow, and the keyboard prints the word, so it stays Backspace. Modifiers come in Apple's order (⌃⌥⇧⌘) on both, whatever order the string names them in.
| Key | Apple | Windows & Linux |
|---|---|---|
mod / meta | Ctrl / Meta | |
ctrl | Ctrl | |
alt | Alt | |
shift | ||
enter | ||
backspace | Backspace | |
tab | ||
arrowup (and the other arrows) | ||
escape, space | Esc, Space | Esc, Space |
The markup is the HTML spec's for a key combination: an outer <kbd> holding one <kbd> per key, with no + between them.
<kbd class="inline-flex gap-0.5" dir="ltr">
<kbd class="…cap…"><svg aria-hidden="true">…</svg><span class="sr-only">Command</span></kbd>
<kbd class="…cap…">K</kbd>
</kbd>- Styling.
variant,sizeandcolorstyle every cap, so a single-character cap stays square. The outer<kbd>is an unstyled row. - The other props (
className,testId,aria-*, …) go on the outer<kbd>, the element a layout places.asChildmakes its child that outer element, with the caps inside it. - Direction. The row is
dir="ltr": a combination reads left to right on a right-to-left page too. - Server rendering. The server can't know the platform, so it renders the non-Apple caps and hydration corrects them on Apple devices.
- Plain text. For a
titleor a tooltip,formatHotkeywrites the same keys as one string (⌘K,Ctrl K), andhotkeyKeyslists them.
The caps are the content, so hotkey takes no children.
Translations
The words a hotkey cap shows (Ctrl, Esc) and the names a drawn cap is spoken by ("Command", "Up Arrow") are English by default. translations replaces them per key; the keys you leave out stay English. A visible word is read as itself, so translating it translates what a screen reader says too.
Code
const german = { ctrl: "Strg", del: "Entf", enter: "Eingabe", escape: "Esc", up: "Pfeil nach oben" }
const french = { escape: "Échap", enter: "Entrée", return: "Retour", command: "Commande", shift: "Maj", up: "Flèche haut" }
const hotkeys = ["mod+shift+delete", "mod+enter", "escape", "arrowup"]
{hotkeys.map((hotkey) => <Kbd key={hotkey} hotkey={hotkey} translations={german} />)}
{hotkeys.map((hotkey) => <Kbd key={hotkey} hotkey={hotkey} translations={french} />)}Off Apple the German row shows Strg Shift Entf. On a Mac it shows glyphs and speaks Apple's names, which german leaves in English ("Shift Command Forward Delete"): set command and forwardDelete too to cover both platforms.
Apple and the other platforms name some keys differently, so each spelling is its own key, named after the English string it replaces: ↵ is spoken "Return" on a Mac (return) and "Enter" elsewhere (enter). Apple's glyphs (⌘ ⇧ ⌦) aren't words and never change. Intl has no display names for keys, so there is nothing to derive from the locale; the kit ships these English defaults as KBD_DEFAULT_TRANSLATIONS and leaves the other languages to you.
import { KBD_DEFAULT_TRANSLATIONS, type KbdTranslations } from '@42-central/ui-react/kbd';| Key | Default | Apple | Windows & Linux |
|---|---|---|---|
command | "Command" | ⌘, spoken | |
meta | "Meta" | Meta, shown | |
control | "Control" | ⌃, spoken | |
ctrl | "Ctrl" | Ctrl (and mod), shown | |
option | "Option" | ⌥, spoken | |
alt | "Alt" | Alt, shown | |
shift | "Shift" | ⇧, spoken | ⇧, spoken |
return | "Return" | ↵, spoken | |
enter | "Enter" | ↵, spoken | |
delete | "Delete" | ⌫, spoken | |
backspace | "Backspace" | Backspace, shown | |
forwardDelete | "Forward Delete" | ⌦, spoken | |
del | "Del" | Del, shown | |
tab | "Tab" | ⇥, spoken | ⇥, spoken |
up, down, left, right | "Up Arrow", "Down Arrow", "Left Arrow", "Right Arrow" | ↑ ↓ ← →, spoken | ↑ ↓ ← →, spoken |
escape | "Esc" | Esc, shown | Esc, shown |
space | "Space" | Space, shown | Space, shown |
pageUp, pageDown | "PgUp", "PgDn" | PgUp, PgDn, shown | PgUp, PgDn, shown |
"Spoken" is a cap drawn as an icon or a glyph, whose name is visually hidden text; "shown" is a word cap, read as itself. Letters, digits and punctuation are shown as typed. For plain text, pass the same object to formatHotkey and hotkeyKeys, and the text reads like the caps. Spotlight takes these words as its own translations.kbd and forwards them to its footer.
Composing chords
A chord is just a row of keys. Render one Kbd per key and separate them with a +:
⌘ + ⇧ + P
Code
<span className="inline-flex items-center gap-1">
<Kbd>⌘</Kbd> + <Kbd>⇧</Kbd> + <Kbd>P</Kbd>
</span>API
Prop
Type
All other props are forwarded to the underlying <kbd> (or asChild element).
Accessibility
Kbd renders a semantic <kbd> element, the right markup for user input / keyboard keys. With hotkey, a key drawn as an icon is aria-hidden and carries its name as visually hidden text, in the platform's own words: "Command", "Shift", "Return" on a Mac, "Shift", "Enter", "Tab" elsewhere, or the words you give translations. So "mod+k" reads "Command K", and "Ctrl K" off Apple. A key written as a word reads as itself. If you draw a symbol yourself (<Kbd>⌘</Kbd>), screen readers may read it inconsistently; prefer hotkey. It is a display element — no hover treatment, no click handling. If a key should be operable (a clickable shortcut row), use asChild with a real <button> so semantics line up; the kit's focus ring rides along, so the key is keyboard-visible without any className of your own:
<Kbd asChild>
<button type="button" onClick={openPalette}>
⌘K
</button>
</Kbd>Changelog
- #490
Inline code and single keys read left to right on RTL pages
- #427
Components in an input slot keep their own icon size: a
KbdinendSlotno longer draws ⌘ at 16px, and asize-*class on a slotted icon now wins
- #410
The footer draws its hints as
<Kbd hotkey>caps with terse labels, translated throughtranslations.kbd - #401
<Kbd hotkey="mod+k" />draws auseHotkeystring for the visitor's platform as one key cap per key with icons and spoken names;formatHotkey()andhotkeyKeys()return the same keys as text - #410
translationson<Kbd hotkey>replaces the words its caps show and speak ("Strg", "Flèche haut"), merged per key ontoKBD_DEFAULT_TRANSLATIONS - #401
A single character or lone icon is a square cap at every size
- #302
Kbdis redesigned as a key cap: one type step larger per size (12/14/16px), regular weight, a visible fill in light mode, a softer label and a shaded bottom edge. The API is unchanged
- #193
Reconcile the card border and withBorder dividers to one hairline
- #142
Carry the kit's focus ring, so composing one onto a real control with
asChildis keyboard-visible
- #37
Correct dark-mode border shades on Kbd, Notification, FileUpload and ChoiceCardGroup
Kbd: keyboard-key labels