Vanilla Breeze v0.7.4

Vanilla Breeze v0.7.4 released

0.7.4 gives the Ambient pack weather. A page names one feed URL on its own site, and the pack sets data-weather from it, uses its sunrise and sunset for dawn and dusk, and never shows a stale observation. Helpers for producing the feed from Open-Meteo are included. Ambient p…

Read the release notes

kbd

The kbd element represents user keyboard input, displaying keys and key combinations in a distinctive style that resembles physical keyboard keys.

Description

The <kbd> element represents keyboard input from the user. VB styles it with a raised appearance resembling physical keyboard keys — monospace font, border, and a subtle box-shadow. It is part of VB's code-family styling alongside <code>, <samp>, and <var>.

When to Use

  • Keyboard shortcuts: Document hotkeys and shortcut combinations
  • Form instructions: Explain keyboard navigation
  • Application tutorials: Guide users through keyboard interactions
  • Accessibility documentation: Document keyboard-accessible controls

When NOT to Use

  • For programming code — use <code>
  • For program output — use <samp>
  • For variables — use <var>

Examples

Nested kbd

The HTML spec uses nesting to mean one input made of several keys: the outer <kbd> is the whole sequence or combination, each inner <kbd> is one key. VB draws the cap on the inner elements only. A <kbd> that has a <kbd> child loses its own border, background, shadow and padding and keeps the surrounding text size, so the inner caps are the same size as a standalone cap.

Separate <kbd> elements with a + between them (<kbd>Ctrl</kbd> + <kbd>S</kbd>) read the same and need no wrapper. Use the nested form when the combination needs to be one element, for example to style or select it as a unit.

Platform-aware shortcuts

Add data-hotkey to have VB render the right keys for the reader's platform: ⌘K on a Mac, Ctrl+K elsewhere. The text you write is the fallback before JavaScript runs. VB replaces it with nested caps and a visually hidden spoken form ("Command K").

Named keys get short labels (escape → Esc, arrowup → ↑, pageup → PgUp). Write the plus key as plus or ctrl++. To localise key names, set data-label-ctrl="Strg" (or any data-label-key) on the element or on <html>. The attribute page has the full mapping.

Key caps inside buttons

A button sets its own text colour, which can be white on a primary fill. Inside button, .button and [role="button"], a cap therefore keeps the button's text colour. Its edge and a translucent fill are derived from that colour, so the cap is always at least as legible as the button label.

CSS Reference

The border and box-shadow create a 3D key-cap appearance. Browser translation will translate key names unless you add the HTML translate="no" attribute: <kbd translate="no">Ctrl</kbd>.

Accessibility

  • Screen readers announce <kbd> as plain text — the key-cap styling is not conveyed, so the surrounding words must say it is a key
  • Use the plus symbol (+) between keys in combinations for clarity
  • Mac glyphs (⌘ ⌥ ⇧ ⌃) are read inconsistently by screen readers. Spell the names out in hand-written text, or use data-hotkey, which adds a visually hidden spoken form
  • Do not put aria-label on <kbd>: it has a generic role, so the label is prohibited and usually ignored
  • Provide context: "Press X to do Y"
  • Document shortcuts in a discoverable location
  • Always provide alternative methods for keyboard-shortcut-only actions

Components Using kbd

VB web components that display keyboard shortcuts use <kbd> styling:

Related

  • <code> — For programming code (shared var(--font-mono))
  • <samp> — For sample program output
  • <var> — For variables in code or math
  • Internationalization — Translation protection for code-family elements
↑