Keyboard Key
Shows a key or a shortcut next to the command it runs, in menus, tooltips and help text.
Ritla scan of this preview: 41 of 41 checks3 breakpointsScanned
Preview
Mirrored is the same English content laid out right to left: it separates a mirroring bug from a translation one.
Installation
Add the component
npx ritla add kbdAlso works with shadcn:
npx shadcn@latest add @ritla/kbdOr copy by hand
Installing by hand copies the component's source into your project. The source comes with a Ritla UI license, so the CLI is the short way to the same files.
Usage
import { Kbd, KeyboardShortcut } from "@/components/ui/kbd";<KeyboardShortcut keys={["Ctrl", "K"]} /><Kbd size="lg">Enter</Kbd>Examples
API reference
Kbd
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | None | Figma's Label: the key as printed. |
size | "sm" | "md" | "lg" | "md" | Figma's Size: 20, 24 or 32px. |
KeyboardShortcut
| Prop | Type | Default | Description |
|---|---|---|---|
keys | ReactNode[] | None | The keys, in order. |
size | "sm" | "md" | "lg" | "md" | Each key's size. |
Usage guidelines
A keyboard key shows a shortcut the way it looks on the keyboard. Where shortcuts belong, labeling keys, combinations and sequences, how they stay left to right in Arabic, and the checks before handoff.
1. Where shortcuts belong
Show a shortcut next to the command it runs, where people already look for that command. Shortcuts help people on a keyboard; they are hints, never the only way to do something.
| Place | Size | Why |
|---|---|---|
| Menu item, at the inline end | sm | People learn the shortcut while they use the menu. |
| Tooltip on an icon button | sm | The tooltip names the action and its shortcut together. |
| Command bar results and search fields | sm | Shows how to open or run a command without the mouse. |
| Help text and onboarding sentences | md | Matches body text in size. |
| A keyboard shortcuts page or dialog | md or lg | Keys are the content, so they can be larger. |
| Touch-only screens | None | There is no keyboard to press. |
2. Labeling keys
Print each key the way it appears on the keyboard. Follow the platform: ⌘ and ⌥ on Mac, Ctrl and Alt on Windows and Linux. Spell out keys whose symbols people may not know, and show letters in capitals.
One key per key
Opening the command bar.
Do
- Show the keys for the platform people use: ⌘ K on Mac, Ctrl K on Windows.
- Spell out Shift, Enter, Esc, Tab and Space.
- Use capital letters: K, not k.
- Put modifiers first, in a fixed order: Ctrl, Alt, Shift, then the key.
Don't
- Use symbols such as ^ or ⏎ that people have to decode.
- Show Mac keys to Windows users.
- Put a whole shortcut in one key: Ctrl+Shift+P.
3. Combinations and sequences
Keys pressed together sit in a row 4px apart, with no plus signs. Keys pressed one after the other are a sequence: put the word then between them.
Together or one after the other
Going to the inbox.
Do
- Put keys pressed together 4px apart.
- Write then between the steps of a sequence: G then I.
- Keep shortcuts to two or three keys.
Don't
- Add plus signs between keys in a row.
- Show a sequence as if the keys were pressed together.
- Use shortcuts that clash with the browser or a screen reader.
4. Arabic and RTL
Keys are the same on Arabic keyboards: Ctrl, Shift and the Latin letter printed on the key. The sentence around a shortcut mirrors; the shortcut itself stays left to right, so Ctrl comes before K in both languages.
The sentence mirrors, the shortcut doesn't
Press Ctrl K to search, in Arabic.
Before handoff
- Each shortcut sits next to its command.
- Keys match the platform, one key per Keyboard key.
- Sequences use then.
- Arabic sentences keep the shortcut left to right.
- No shortcut is the only way to run a command.
Accessibility
ARIA
- Each key is a
<kbd>, and the shortcut a<kbd>around them. Write Ctrl, not ^: screen readers read the names. - They aren't buttons; don't show them on touch-only screens.
Do
- Mark each key as
<kbd>and the whole shortcut as one outer<kbd>. - Give symbols a spoken name: ⌘ reads as Command.
- Make every shortcut command reachable another way.
- Let people turn off or remap single-key shortcuts.
Don't
- Make a keyboard key clickable.
- Override browser or screen reader shortcuts.
- Show a shortcut that doesn't work on the current platform.
Arabic and RTL notes
Mirrors
- The sentence around the shortcut mirrors.
Does not mirror
- The key order stays left to right inside Arabic text (Ctrl, then K).
- Numerals
- Keys as printed; digits aren't converted.
- Arabic typography
label-12Medium (label-14at lg).- Mixed-direction text
- The shortcut is isolated LTR.
Do
- Keep key names in English: Ctrl, not a translation.
- Keep a shortcut left to right inside an Arabic sentence.
- Show the Latin letter; Arabic keyboards print it beside the Arabic one.
- Write the sentence natively in Arabic, not translated.
Don't
- Reverse the key order in Arabic.
- Translate key names.
- Replace the letter with the Arabic letter on the key.
Checks it passes
The Ritla checks this component satisfies by construction. Used as documented, it does not bring these defects onto your page.
- Clipped text: content wider than its box with overflow hidden and no ellipsis
- Fixed-pixel-width container whose Arabic text exceeds the space
- Arabic text falling back past the declared font family (measured, declared, or a webfont that failed to load)
- letter-spacing applied to Arabic text (breaks the connected script)