---
title: Kbd
description: Display one keyboard key as shortcut notation.
package: moraine
version: 0.11.0
repository: https://github.com/subframe7536/moraine
---

# Kbd

> Display one keyboard key as shortcut notation.

## Anatomy

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

## Usage

Use Kbd to display one key in a shortcut hint. Combine keys with [KbdGroup](https://moraine.subf.dev/components/kbd-group.md).
Showing a shortcut does not register a keyboard handler.

```tsx
import { Kbd } from 'moraine'

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

### Key aliases

Known aliases such as `meta`, `command`, `shift`, `escape`, and `arrowup` resolve to a symbol or
short label (`⌘`, `⇧`, `Esc`, `↑`), matched case-insensitively. Any other value renders as written.
Pass `symbol={false}` to render the value as written instead. An alias also gets a spoken name from
the locale messages; `translations` overrides it per instance. Set `aria-label` when assistive
technology needs a different name than the visible keycap. It takes precedence over the alias name.

```tsx
<Kbd value="meta" />
<Kbd value="escape" symbol={false} />
<Kbd value="K" aria-label="Search" />
```

### Root styling

`Kbd` renders one `<kbd>` root, so use `class` and `style` for an individual keycap. Configure
`kbd.base.root` in your Theme to share keycap presentation. `variant` (`default`, `outline`,
`invert`) and `size` (`sm`, `md`, `lg`) select the built-in treatments. `root` is the only slot, so
`classes` and `styles` only duplicate `class` and `style`.

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

## Examples

### Hint search and cancel shortcuts

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

```tsx
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>
  )
}
```

### Show how to close a dialog

Use a single `Kbd` when the hint is one key rather than a chord.

```tsx
import { Kbd } from 'moraine'

export function ShortcutComposition() {
  return (
    <p class="text-sm text-foreground flex flex-wrap gap-2 items-center">
      Close dialogs with
      <Kbd value="escape" />
    </p>
  )
}
```

## API Reference

### Props

Props for the Kbd component.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| aria-label | string \| undefined | — | Accessible label for the keycap. Overrides the spoken name of a key alias; plain keys have no `aria-label` unless set. |
| size | 'sm' \| 'md' \| 'lg' \| undefined | 'md' | Visual size of the component. |
| symbol | boolean \| undefined | true | Whether to resolve known key aliases to symbols. |
| translations | Translations \| undefined | — | Localized spoken names for key aliases, keyed by alias such as `meta` or `escape`. Used as the `aria-label` when `value` is an alias and `aria-label` is not set. |
| value* | Key | — | The key to display. A name matching a built-in alias, compared case-insensitively<br>(`meta`, `ctrl`, `shift`, `escape`, `arrowup`, ...), shows its symbol or short label, such as `⌘` for<br>`meta` or `Esc` for `escape`, unless `symbol` is `false`. Any other string renders as written, such as `K` or `F5`.<br>Nothing renders for an empty string. |
| variant | 'default' \| 'outline' \| 'invert' \| undefined | 'default' | Visual treatment of the component. |
| class | SlotClassValue \| undefined | — | Class applied to the component root or trigger element. |
| classes | Classes \| undefined | — | Family slot class defaults for this instance. |
| style | SlotStyleValue \| undefined | — | Style applied to the component root or trigger element. |
| styles | Styles \| undefined | — | Family slot style defaults for this instance. |
