Skip to the page
TACTILE UI

Kit part · Buttons

Kbd

The key to press, drawn as the key: a small cap on a skirt with a dish worked into its top. Shortcuts come as combos and follow the platform, so ⌘ K on a Mac is Ctrl K elsewhere.

Element
<kbd>
Needs
kit.css + kit.mjs
Rules
kbd.rules.md · 4
Finishes
Aluminium · Graphite · Porcelain · Black
Volumes
Tactile · Quiet
On this page
  1. Variants
  2. Every state, at once
  3. API
  4. Markup
  5. Accessibility
  6. How it’s built
  7. Rules
  8. Related parts
01

Variants

KKK
Sizes · 18 · 22 · 30
CtrlShiftP
A combo
Alt↑
With plus signs
SpaceEnter
Wide · space, enter

Press Esc to close it, or Tab to move on.

In a sentence
CommandKCtrlK
For the platform · Mac and PC
02

Every state, at once

Both finishes, side by side. Hover, pressed and focus are forced with .is-hover, .is-down and .is-focus; checked and disabled are real.

Aluminium

PartRestHeld down
18 pxKK
22 pxKK
30 pxKK
WideSpaceSpace

Graphite

PartRestHeld down
18 pxKK
22 pxKK
30 pxKK
WideSpaceSpace
03

API

NameKindValuesWhat it does
.tui-kbdclasson <kbd>A cap: 22px tall, a skirt below, a dish inside. Printed in the second ink, in the sans, never the mono.
--sm · --lg · --wideclass18 · 30 px · 3× wideSizes; wide is for Space and other long keys.
.tui-kbd-comboclassaround several capsA shortcut: caps 3px apart.
.tui-kbd-combo__plusclassaria-hiddenA printed + between caps, for teaching a combo.
.tui-kbd__nameclassinside a symbol capThe spoken name: “Command” for ⌘. Not drawn.
data-kbd · data-kbd-size · data-kbd-plusattribute"Mod+K" · "sm" · —On any element: kit.mjs fills it with the caps for the visitor’s platform.
Modkey name⌘ · CtrlThe platform’s main modifier. Others: Ctrl, Alt, Shift, Enter, Esc, Tab, Space, Backspace, Delete, Up, Down, Left, Right.
data-kbd-liveattributeon a containerThe caps inside sink while their real keys are held.
kbdLabels(shortcut, { mac }) · kbdHTML(shortcut, options)functionkit.mjsThe parts of a shortcut, and its markup. Pure: the platform is an argument.
wireKbd(root)functionkit.mjsFill every [data-kbd] under root. Runs once on load; call it for markup you add later.
04

Markup

<!-- One cap per key -->
<span class="tui-kbd-combo"><kbd class="tui-kbd">Ctrl</kbd><kbd class="tui-kbd">K</kbd></span>

<!-- Or let the script pick the keys for the platform: ⌘ K on a Mac, Ctrl K elsewhere -->
<span data-kbd="Mod+K"></span>
<span data-kbd="Mod+Shift+P" data-kbd-size="sm" data-kbd-plus></span>

<!-- Inside a sentence -->
<p>Press <kbd class="tui-kbd tui-kbd--sm">Esc</kbd> to close it.</p>

<!-- A symbol names itself for a screen reader -->
<kbd class="tui-kbd"><span aria-hidden="true">⌘</span><span class="tui-kbd__name">Command</span></kbd>
import { kbdLabels, kbdHTML, wireKbd } from '/kit/kit.mjs';

kbdLabels('Mod+Shift+K', { mac: true });
// [{ text: '⌘', name: 'Command', key: 'meta' }, { text: '⇧', … }, { text: 'K', … }]

el.innerHTML = kbdHTML('Mod+K', { size: 'sm', plus: true });
wireKbd(container);   // fills every [data-kbd] under it

Needs kit.css and kit.mjs. How to install the kit.

05

Accessibility

  • A <kbd> is text, not a control: it is not focusable and it does nothing. To press something, use a key.
  • A symbol cap is hidden from assistive technology and its name is spoken instead, so ⌘ is read “Command” and ⇧ “Shift”, not by their code points.
  • The cap is 22px tall at its default size and the label inside is 11px semibold in the second ink, so it stays legible in both finishes.
  • Where a shortcut differs by platform, the visitor sees their own; do not print the Mac symbols to everyone.
  • The pressed state is a second cue, never the only one: it changes with a real key press and is not needed to use a page.
06

How it’s built

A cap is the key’s own anatomy scaled down: a face gradient with the catch-light along its top edge, a skirt of the darker metal one or two pixels below, and a shadow under that. Its dish is a second, lower face inset 2px (concentric with the cap, so its corner is the cap’s less the rim) with a soft shadow along its upper wall. Held, the cap drops by the height of its skirt and takes the pressed light, exactly as a key does. kbd.mjs holds a small table of key names, each with its Mac glyph, its printed word elsewhere and what to say aloud; the rest is arithmetic and string-building, exported for tests.

07

Rules

kbd.rules.mdIn the brain

Show the keys, not the letters: a cap for each key, right for the platform, named for a screen reader.

4 rules in this file, with the foundations they rest on and the anti-patterns that break them. Full rules ship in the brain with the Pass.

08

Key

Every button, and every link that acts like one: a cap on a skirt that drops below the plate when pressed.

2 matches
BatteryGB
Set battery reserve

Command palette

Every action and page behind one key: a modal plate whose entry line is a lit display, with the results printed below and the chosen one pressed in.

Menu

A card of actions and options that slides out from under its key. The key stays down while the card is out; an option that is on lights its lamp.

Docs
Finish
Volume