v0.5.1

Kbd

Keyboard shortcut indicator displaying key combinations.

⌘K

Installation

npx paubha@latest add kbd

Usage

import { Kbd, KbdGroup } from "@/components/ui/kbd";

<KbdGroup>
  <Kbd>⌘</Kbd>
  <Kbd>K</Kbd>
</KbdGroup>

Examples

Single key

Esc

Three keys

⌘⇧K

In a menu item

Search⌘K

API reference

Kbd

PropTypeDefaultDescription
childrenReactNode—The key label, e.g. a letter, symbol, or word like "Esc".

KbdGroup

PropTypeDefaultDescription
childrenReactNode—One or more Kbd elements. A decorative "+" is inserted between each.

Accessibility

Accessibility

  • Semantic element. Renders a native <kbd> element, which screen readers announce as the key name.

  • Decorative usage. When shown next to a menu item or tooltip purely as a hint (not the primary label), wrap the group in aria-hidden so it isn't announced twice. Expose the real shortcut on the control itself with aria-keyshortcuts.

  • Not interactive. Kbd is static text: no role, no tab stop, no focus state.

  • Separator. The "+" between keys in KbdGroup is decorative and marked aria-hidden.

  • Contrast. Uses fg-secondary on bg-secondary, which meets contrast requirements in both light and dark mode.

When to use

Use to display keyboard shortcuts: in tooltips, docs, or menu items. Shows a visual representation of key combinations.

Do:

  • Use platform-appropriate symbols (⌘ on Mac, Ctrl on Windows)
  • Place near the action it triggers
  • Keep combinations simple (3 keys or fewer)

Don't:

  • Show shortcuts that don't actually work
  • Use Kbd purely decoratively with no real shortcut behind it
  • Conflict with existing browser or OS shortcuts