# Kbd: keyboard keys and shortcuts in CSS

> iVOLT kbd: key caps for shortcuts in docs, menus and command hints, lit like a real key, in three sizes and both themes. Native kbd element, no JavaScript.

Source: https://ivolt.intervolutions.com/components/kbd · iVOLT 1.1.2 · English

A key cap for the keys a reader has to press: `Ctrl`, `K`, `Esc`. It styles the native `<kbd>` element, so the meaning — “keyboard input” — is already in the markup, and the look is a small raised cap lit from above, tinted with the brand in both themes.

**CSS:** `css/components/kbd.css` (in `ivolt.css`). **JS:** none. New in 1.1.

Couldn't load the demo. [Open alone](https://ivolt.intervolutions.com/stage/kbd/basic.html?id=fx-kbd-basic)

```html
<div class="iv-stack iv-u-gap-5">
  <p class="iv-u-m-0">Open the command palette with <span class="iv-kbd-group"><kbd class="iv-kbd">Ctrl</kbd>+<kbd class="iv-kbd">K</kbd></span>, move with <kbd class="iv-kbd">↑</kbd> <kbd class="iv-kbd">↓</kbd> and confirm with <kbd class="iv-kbd">Enter</kbd>. <kbd class="iv-kbd">Esc</kbd> closes it.</p>

  <dl class="iv-dl iv-dl--compact" style="max-width: 30rem">
    <div class="iv-dl__row"><dt>Search the docs</dt><dd><span class="iv-kbd-group"><kbd class="iv-kbd">/</kbd></span></dd></div>
    <div class="iv-dl__row"><dt>Toggle the theme</dt><dd><span class="iv-kbd-group"><kbd class="iv-kbd">Shift</kbd>+<kbd class="iv-kbd">T</kbd></span></dd></div>
    <div class="iv-dl__row"><dt>Copy the snippet</dt><dd><span class="iv-kbd-group"><kbd class="iv-kbd">⌘</kbd>+<kbd class="iv-kbd">C</kbd></span></dd></div>
  </dl>

  <div class="iv-cluster iv-u-items-center">
    <kbd class="iv-kbd iv-kbd--sm">Tab</kbd>
    <kbd class="iv-kbd">Tab</kbd>
    <kbd class="iv-kbd iv-kbd--lg">Tab</kbd>
  </div>

  <p class="iv-u-m-0 iv-u-text-sm iv-u-text-muted">The shortcuts above are examples; this page binds none of them.</p>
</div>
```

## When to use it

Use `iv-kbd` wherever a sentence names a key: a shortcut in a menu item, a hint under a search field (“press `Ctrl`+`K` to search”), the keyboard table of a component page, the footer of a command palette. It is text, not a control: nothing happens when it is clicked, and it should never be the only way to learn that a shortcut exists.

A shortcut made of several keys goes in `iv-kbd-group`, which spaces the caps and keeps them on one line. The `+` between them is written by you, as plain text, so it is read aloud and copied with the rest of the sentence. For a sequence (press `G` then `H`) write “then” instead of a plus sign.

## Sizes

The default cap is `1.625rem` tall and fits body text. `iv-kbd--sm` sits inside small print and table cells; `iv-kbd--lg` is for a hero or an onboarding step where the key is the point of the sentence. All three scale with `--iv-kbd-size`, so a size of your own is one local, not a new class.

## Accessibility

- Write the key the way it is labelled on the keyboard: `Ctrl`, `Shift`, `Enter`. Symbols such as `⌘` or `↑` are read inconsistently by screen readers; next to an unusual symbol, add the name in visually hidden text (`<span class="iv-u-sr-only">Command</span>`).
- Say which platform a shortcut belongs to when it differs (“`⌘`+`K` on macOS, `Ctrl`+`K` elsewhere”).
- If an element really has a shortcut, declare it on the element with `aria-keyshortcuts`; the cap only shows it.
- The cap keeps a border in forced colours, so it still reads as a key in Windows high-contrast mode.

## Customising

The cap reads the theme: the face is the raised surface, the skirt a step darker, the letters the text colour, and the brand tint comes from `--iv-color-primary`, so a one-colour theme recolours it too. The only local is the size:

```
.palette-footer { --iv-kbd-size: 1.375rem; }
```

In the layer-free sheet (`ivolt.flat.css`) the base rule for `kbd` weighs (0,1,0) since 1.1, so the component wins by order there too.

## Common mistakes

- Wrapping a whole sentence in `<kbd>`: only the keys are keyboard input.
- Drawing the `+` with CSS: it disappears from copy-paste and from speech.
- Using a cap as a button. If clicking it should do something, it is an [`iv-button`](https://ivolt.intervolutions.com/components/button).
- Listing a shortcut the page does not bind. The fixture above says so in plain words; your pages should not promise keys that do nothing.

## Class index

Every class of the family. The full list per stylesheet lives in the [reference](https://ivolt.intervolutions.com/reference).

| Class | What it does |
| --- | --- |
| `iv-kbd` | A key cap on a `<kbd>` element. |
| `iv-kbd--sm` | Small cap for small print and table cells. |
| `iv-kbd--lg` | Large cap for a hero or an onboarding step. |
| `iv-kbd-group` | Keeps the keys of one shortcut together, with the author's `+` between them. |
