# Kbd

Kbd is a headless component that renders a `<kbd>` element to display keyboard shortcuts and key combinations in a styled inline element. It semantically marks up user keyboard input.

**Status:** beta — implemented and unit-tested in all seven frameworks with an axe-clean demo page; not yet exercised in composed flows.

Use this component to display keyboard shortcuts, key combinations, or individual key references in documentation, tooltips, or help text.

## Implementation Notes

- Renders a native `<kbd>` HTML element for semantic keyboard input markup
- Accepts `className` for CSS class targeting
- Spreads `restProps` onto the `<kbd>` element for consumer customization
- Children slot renders the key label text

## Props

- `className`: string (default: `""`) -- CSS class name for the element
- `label`: string (optional) -- spoken form, for a glyph such as ⌘: hidden text, with the visible key `aria-hidden`
- `children`: slot (required) -- the key label text content
- `...restProps`: unknown -- additional attributes spread onto the `<kbd>` element

## Usage

Key combination for copy:

```html
<kbd>Ctrl</kbd> + <kbd>C</kbd>
```

Inline shortcut reference in help text:

```html
Press <kbd>Enter</kbd> to submit the form.
```

Menu item with keyboard shortcut:

```html
<menuitem>
  Save
  <span class="shortcut"><kbd>Ctrl</kbd> + <kbd>S</kbd></span>
</menuitem>
```

Multi-key shortcut in a keyboard shortcuts panel:

```html
<SummaryList>
  <SummaryListItem>
    <dt>Open command palette</dt>
    <dd><kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>P</kbd></dd>
  </SummaryListItem>
  <SummaryListItem>
    <dt>Toggle sidebar</dt>
    <dd><kbd>Ctrl</kbd> + <kbd>B</kbd></dd>
  </SummaryListItem>
</SummaryList>
```

## Keyboard Interactions

None. Kbd is a passive display element.

## ARIA

No ARIA attributes needed. The `<kbd>` element has built-in semantics for keyboard input. With `label`, the visible key is `aria-hidden` and the label is hidden text, the spoken form.

## When to Use

- Use to display keyboard shortcuts, key combinations, or key references.
- Use in documentation, help text, tooltips, or command palettes.
- Use in application menus where shortcuts are shown alongside menu items.
- Use in onboarding flows to teach users keyboard shortcuts.

## When Not to Use

- Do not use for code snippets or programming syntax -- use Code or CodeBlock instead.
- Do not use for general emphasis -- use `<strong>` or `<em>` instead.
- Do not use for non-keyboard input such as mouse actions or gestures.

## Headless

This headless component renders a `<kbd>` element. The consumer provides all visual styling including borders, backgrounds, padding, border-radius, and font styling to create a keycap appearance.

## Styles

The consumer provides all CSS styling. The component renders with a `.kbd` class for targeting. Common styling includes a keycap appearance with borders, shadows, and monospace font.

## Testing

- Verify the component renders a `<kbd>` element
- Verify children content is rendered
- Verify pass-through attributes are applied

## Advice

- **Designers**: Style Kbd elements to look like physical keycaps with borders, subtle shadows, and rounded corners. Use a monospace font for consistency.
- **Developers**: Nest `<Kbd>` elements for key combinations (e.g., `<Kbd>Ctrl</Kbd> + <Kbd>C</Kbd>`). Use the `<kbd>` semantic for screen readers.

## Related components

- `code` — an inline code span for displaying short code snippets within surrounding text
- `code-block` — a block of formatted code with optional line numbers and line highlighting

## Known limitations

None known.

## References

- MDN kbd element: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/kbd

---

Lily™ and Lily Design System™ are trademarks.
