Skip to content
English

How it works

Renders the semantic nesting browsers expect: an outer kbd for the shortcut and one inner kbd per key. A raised cap is a faint vertical gradient with a hairline and a 2px skirt drawn as an inset shadow, so it reads as a physical key without a heavy border; glyph keys are square and word keys get side padding. Pressing a cap sinks the face by the skirt height on a short spring and tints it with the accent. In the demo the rows play their shortcuts in turn, and pressing keys on your own keyboard lights the matching row.

Use it for

  • Shortcut hints in menus, tooltips, command palettes and help pages.
  • Onboarding that teaches a shortcut by showing the keys being pressed.

Look elsewhere when

  • Touch-only interfaces where there is no keyboard to press.

Usage

import { Kbd } from './Kbd.jsx'

const isApple = typeof navigator !== 'undefined' && /Mac|iPhone|iPad/.test(navigator.platform)

export function SearchHint() {
  return (
    <p>
      Press <Kbd shortcut="mod+k" platform={isApple ? 'mac' : 'other'} /> to search, or <Kbd shortcut="g then i" /> for the inbox.
    </p>
  )
}

Props

PropTypeDefaultWhat it does
shortcutstring | string[][]—Keys joined with + and steps with “then” or a comma: 'mod+shift+p', 'g then i'. Named keys: mod, cmd, ctrl, alt, shift, enter, esc, tab, backspace, space and the four arrows; other keys show as typed, single letters upper-cased.
childrenReactNode—Without shortcut, a single cap with your own content.
platform'mac' | 'other''mac'Apple glyphs (⌘ ⌥ ⇧) or words (Ctrl, Alt, Shift); mod maps to Command or Ctrl. Decide it after mount to avoid a hydration mismatch.
size / variant'sm' | 'md' | 'lg' / 'raised' | 'flat''md' / 'raised'22, 26 or 40px caps; raised has a physical skirt, flat is a quiet chip for menus.
pressedboolean | string[]falseSinks every cap, or only the listed keys.
thenLabelstring'then'Word between steps, shown and spoken.

Accessibility

  • The outer kbd carries an aria-label with spoken key names (“Command Shift P”), because glyphs such as ⌘ are read inconsistently; the caps themselves are hidden from screen readers.
  • The word between steps is part of the spoken label.
  • Caps are not interactive; pressing state is visual only.
  • Reduced motion keeps the colour change and removes the sink.

Motion

Press: 140ms spring sink by the skirt height with a colour fade.

Add it to your project

Copy the prompt into Codex or Claude Code. The agent reads the published source, shows you what it will write and adds the component next to your own.

Kbd.jsxkbd.csstokens.cssREADME.md

Both files install together. The stylesheet reads the design tokens in tokens.css and carries fallbacks, so it also works alone.

Data display
Code diff comes with Pro. Its preview shows once you unlock it.
Flip countdown comes with Pro. Its preview shows once you unlock it.