Repo

Kbd renders a single keyboard key. Wrap several in KbdGroup to show a shortcut such as ⌘K. Both render a <kbd> element — nesting keys inside a group <kbd> is valid HTML and conveys "composite input".

Usage

Esc
<kbd class="zui-kbd">Esc</kbd>

Single keys

Use text labels or symbols (⌘, ⇧, ⌥, ⌃, ⏎, ⌫, ↑).

⌘⇧⌥⏎TabEscF
<kbd class="zui-kbd">⌘</kbd>
<kbd class="zui-kbd">⇧</kbd>
<kbd class="zui-kbd">⌥</kbd>
<kbd class="zui-kbd">⏎</kbd>
<kbd class="zui-kbd">Tab</kbd>
<kbd class="zui-kbd">Esc</kbd>
<kbd class="zui-kbd">F</kbd>

Shortcuts

Wrap keys in KbdGroup. Add a plain <span> between keys for a connector like + or then.

⌘K⌘+⇧+PGthenH
<kbd class="zui-kbd-group">
<kbd class="zui-kbd">⌘</kbd>
<kbd class="zui-kbd">K</kbd>
</kbd>

<kbd class="zui-kbd-group">
<kbd class="zui-kbd">⌘</kbd>
<span>+</span>
<kbd class="zui-kbd">⇧</kbd>
<span>+</span>
<kbd class="zui-kbd">P</kbd>
</kbd>

<kbd class="zui-kbd-group">
<kbd class="zui-kbd">G</kbd>
<span>then</span>
<kbd class="zui-kbd">H</kbd>
</kbd>

In context

Keys scale to the surrounding font size, so they sit naturally inside text, buttons, and tooltips.

Press / to focus search, or ⌘K to open the command palette.

<p>Press <kbd class="zui-kbd">/</kbd> to focus search, or <kbd class="zui-kbd-group"><kbd class="zui-kbd">⌘</kbd><kbd class="zui-kbd">K</kbd></kbd> to open the command palette.</p>

<button class="zui-button zui-button-variant-outline">
Search
<kbd class="zui-kbd-group"><kbd class="zui-kbd">⌘</kbd><kbd class="zui-kbd">K</kbd></kbd>
</button>

Shape

Use the shape prop to change the corners: default (rounded), hard (square), soft (pill) or squircle. A squircle is a rounded square with smooth corners. Browsers without corner-shape support show normal rounded corners.

Esc DefaultEsc HardEsc SoftEsc Squircle
<kbd class="zui-kbd">Esc</kbd>
<kbd class="zui-kbd zui-kbd-shape-hard">Esc</kbd>
<kbd class="zui-kbd zui-kbd-shape-soft">Esc</kbd>
<kbd class="zui-kbd zui-kbd-shape-squircle">Esc</kbd>

To make squircle the default everywhere, add zui-squircle-all to <html> — see Squircle.

CSS custom properties

Set these on :root, on a wrapper, or on the element. See Component custom properties.

Property Default Description
--zui-kbd-bg var(--color-border) Key background
--zui-kbd-color var(--color-text) Key label colour
--zui-kbd-radius var(--radius-md) Border radius
--zui-kbd-font-size var(--step--2) Label font size
--zui-kbd-font-family var(--font-body) Label font family
--zui-kbd-padding-inline var(--space-3xs) Left and right padding

Theme

Copy this CSS to your project: