Kbd
A keyboard shortcut hint rendered as a native kbd element. KbdGroup arranges the separate keys in a shortcut sequence. These components display shortcuts without registering keyboard handlers.
React
Preview
Usage
When to use
- Show a keyboard shortcut beside the action it activates.
- Describe a sequence of keys in instructions.
When not to use
- An interactive key or action. Use Button.
- Registering a keyboard shortcut. Add the handler in your application.
Platform support
What each platform has, from the spec. A selected platform is highlighted.
| Name | Web | iOS | Android | Note |
|---|---|---|---|---|
| size | Yes | Yes | Yes |
Variants
size
Compact shortcut hint: sm is 16px tall and md is 20px tall. Both use 12px UI text.
Examples
Shortcut sequence
Beside an action
Do and don't
Do
- Render each key in its own Kbd and combine keys with KbdGroup.
- Use readable names for symbols that assistive technology may pronounce ambiguously.
Don't
- Do not make Kbd clickable or focusable.
- Do not display a shortcut that the application does not support.
Props
| Name | Type | Values | Default | Description |
|---|---|---|---|---|
| size | enum | sm | md | md | Compact shortcut hint: sm is 16px tall and md is 20px tall. Both use 12px UI text. |
Not generated: KbdGroup.
Slots
| Name | Required | Description |
|---|---|---|
| children | yes | Key label or shortcut symbol. |
Anatomy
| Part | Description |
|---|---|
| root | Compact native kbd with UI type, surface fill, neutral border and secondary text. Small is 16px tall, medium is 20px tall; each has the same minimum width and grows for longer key names. |
| group | Inline KbdGroup wrapper with token spacing between keys. |
Accessibility
Role: none
- Kbd is not focusable and does not take keyboard input.
- Give shortcut symbols readable names, such as aria-label="Command" for ⌘.
- A displayed shortcut is only a hint. The application owns shortcut handling.
Install
npx werewolf-ui add kbdRun npx werewolf-ui init once in your app before adding components. Init sets up tokens, their CSS import and agent rules. Add installs this component and its dependencies while preserving your theme. See Installation for requirements and the alternative registry setup.