Kbd
A keyboard shortcut hint that renders the right modifier for the reader's platform.
Purpose
Show a keyboard shortcut the way the reader's own machine spells it — ⌘K on a Mac, Ctrl+K
on Windows and Linux. Hard-coding ⌘ is the bug this component exists to fix: most of the
portal audience is on Windows, where an Apple glyph is simply wrong.
Open the command palette with Ctrl+K
The prop you almost always want is mod — "the platform's primary command modifier". It maps
exactly to the e.metaKey || e.ctrlKey check a cross-platform handler makes, so the label and
the binding stay in step.
Modifiers
shift, alt and ctrl stack onto mod in any order; the component reorders them to each
platform's convention. Apple renders ⌃⌥⇧⌘ as an unseparated glyph run, everyone else spells
them out and joins with +.
| Command palette | Ctrl+K |
| Redo | Ctrl+Shift+Z |
| Toggle a panel | Alt+T |
Use ctrl only when you mean the literal Control key on every platform. On Apple hardware ⌃ is
a genuinely different key from ⌘, so it is rarely what you want.
Named keys
Enter, Escape, Backspace, Tab and the arrows become their conventional glyphs on Apple
platforms and stay spelled out everywhere else.
In a shortcut slot
Kbd inherits size and colour from its container, so it looks identical to the plain text it
replaces. The CommandShortcut, MenubarShortcut and ContextMenuShortcut slots keep their
ml-auto positioning job; Kbd goes inside.
<MenubarItem>
Redo <MenubarShortcut><Kbd mod shift>Z</Kbd></MenubarShortcut>
</MenubarItem>See it in place on Menubar, Command and Context menu.
Best practices
Do
- Show a hint only for a shortcut you have actually bound —
Kbdis a label and registers nothing. - Bind with
e.metaKey || e.ctrlKeysomodtells the truth on both platforms. - Set
aria-keyshortcutsyourself, on the focusable element, using the canonical list form.
Don't
- Hard-code
⌘in your own copy. - Put
aria-keyshortcutson the<kbd>; it belongs on the thing that takes focus. - Add key-cap borders or backgrounds via
className— menus keep one visual language.
Accessibility & hydration
-
Renders a real
<kbd>, so assistive tech announces it as keyboard input rather than as prose. -
Kbddoes not setaria-keyshortcuts. That attribute belongs on the focusable element, and it must not change after hydration — a screen reader may already have announced it. Use the canonical list form, which the ARIA spec allows, so one static value covers both platforms:<button aria-keyshortcuts="Control+K Meta+K">Search</button>Note the spelling: ARIA wants
Control, while the visible label readsCtrl. Do not copy the on-screen text into the attribute. -
The platform resolves after mount, so the first paint shows the
Ctrlform and Apple users see a one-frame swap. This is deliberate: resolving during render would disagree with the server HTML and React would report a hydration mismatch. This site is a static export, so its HTML is generated once at build time and cannot know the reader's platform. -
The swap changes visible text only, so nothing is re-announced.
Props
Kbd also accepts every native <kbd> attribute.
| Prop | Type | Default | Description |
|---|---|---|---|
mod | boolean | undefined | — | The platform's primary command modifier: ⌘ on Apple, Ctrl everywhere else. This is the one you almost always want — it pairs with the `e.metaKey || e.ctrlKey` check a cross-platform handler makes. |
shift | boolean | undefined | — | The Shift modifier. |
alt | boolean | undefined | — | The Alt/Option modifier. |
ctrl | boolean | undefined | — | The literal Control modifier, on every platform. Rare — on Apple hardware ⌃ is a genuinely different key from ⌘, so reach for `mod` unless you mean Control specifically. |
childrenrequired | React.ReactNode | — | The key itself, e.g. `K`, `Enter`, `ArrowUp`. |