Skip to content

Keyboard Key

Get Ritla UI

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

Open in Figma

Preview

Mirrored is the same English content laid out right to left: it separates a mirroring bug from a translation one.

PreviewCode
EnglishMirroredArabic
LTR →

Installation

  1. Add the component

    npx ritla add kbd

    Also works with shadcn: npx shadcn@latest add @ritla/kbd

  2. Or 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

kbd.tsx
import { Kbd, KeyboardShortcut } from "@/components/ui/kbd";<KeyboardShortcut keys={["Ctrl", "K"]} /><Kbd size="lg">Enter</Kbd>

Examples

Next to commands

Small keys at the end of menu rows; show ⌘ on Mac and Ctrl on Windows.

EnglishMirroredArabic
LTR →

API reference

Kbd

PropTypeDefaultDescription
childrenReactNodeNoneFigma's Label: the key as printed.
size"sm" | "md" | "lg""md"Figma's Size: 20, 24 or 32px.

KeyboardShortcut

PropTypeDefaultDescription
keysReactNode[]NoneThe 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.

PlaceSizeWhy
Menu item, at the inline endsmPeople learn the shortcut while they use the menu.
Tooltip on an icon buttonsmThe tooltip names the action and its shortcut together.
Command bar results and search fieldssmShows how to open or run a command without the mouse.
Help text and onboarding sentencesmdMatches body text in size.
A keyboard shortcuts page or dialogmd or lgKeys are the content, so they can be larger.
Touch-only screensNoneThere 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: Separate keysEach key reads like the keycap people press.
Don't: One key with plus signsA single long key hides where one key ends and the next begins.

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: Sequence with thenPeople press G, let go, then press I.
Don't: Sequence shown as a combinationIt reads as G and I held down together.

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.

Do: Ctrl before KThe sentence reads right to left, and the shortcut still reads Ctrl, then K.
Don't: Reversed keysMirroring the shortcut makes it read K then Ctrl.

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-12 Medium (label-14 at 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.

  • R042Clipped text: content wider than its box with overflow hidden and no ellipsis
  • R043Fixed-pixel-width container whose Arabic text exceeds the space
  • R050Arabic text falling back past the declared font family (measured, declared, or a webfont that failed to load)
  • R051letter-spacing applied to Arabic text (breaks the connected script)