Skip to main content

Kbd

Display one keyboard key as shortcut notation.

Press⌘Kto open command menu
Props
Slots

Anatomy#

Kbd [component; slot=root; <kbd>]

Usage#

Use Kbd to display one key in a shortcut hint. Combine keys with KbdGroup. Showing a shortcut does not register a keyboard handler.

import { Kbd } from 'moraine'

export function Example() {
  return <Kbd value="K" />
}

Key aliases#

Known aliases such as meta, command, shift, escape, and arrowup resolve case-insensitively to a symbol or short label (⌘, ⇧, Esc, ↑) and a spoken name from the locale messages. Any other value renders as written.

  • symbol={false}: renders an alias as written without its spoken name.
  • translations: overrides the spoken alias names per instance.
  • aria-label: sets a custom accessible name and takes precedence over the alias name.
<Kbd value="meta" />
<Kbd value="escape" symbol={false} />
<Kbd value="K" aria-label="Search" />

Root styling#

Kbd renders a single <kbd> root. Use variant ('default', 'outline', or 'invert') and size ('sm', 'md', or 'lg') for built-in treatments.

Use class and style for an individual keycap, or configure kbd.base.root in your Theme for shared defaults. Because root is the only slot, classes and styles duplicate class and style.

<Kbd value="K" class="text-blue-600" />

Examples#

Basic#

Place keycaps in instructional copy. Registration of those shortcuts stays in application code.

import { Kbd } from 'moraine'

export function KbdUsage() {
  return (
    <div class="flex flex-wrap gap-3 items-center">
      <span class="text-sm text-muted-foreground flex gap-1.5 items-center">
        Press <Kbd value="command" /> <Kbd value="k" /> to search
      </span>
      <span class="text-sm text-muted-foreground flex gap-1.5 items-center">
        Press <Kbd value="escape" /> to cancel
      </span>
    </div>
  )
}

API Reference#

Props#

Props for the Kbd component. Renders a <kbd> element by default.

Prop