Data display

Kbd

A keyboard key or shortcut, shown in a small gray box, as in "Press ⌘K to search". Buttons, menu items and inputs render it from their kbd prop; use the tag directly in text.

Press Ctrl K to search.
Blade

A <kbd> with "Ctrl K" in semibold, on a light gray rounded background (translucent white in dark mode), inline with the text.

Without the box #

text drops the background and padding, leaving only the text in the key style, for tight places such as a menu item.

⌘K
Blade

A shortcut for the user's platform #

The shortcut is written as Alpine key modifiers, the same format as the shortcut prop of tk:modal and tk:command.modal, with mod for the platform's main modifier. On macOS and iOS the first shows "⌘K" and the second "⇧⌘P"; on Windows, Linux and Android, "Ctrl K" and "Ctrl Shift P". slash is "/" everywhere.

Press Ctrl K to search. Ctrl Shift P /
Blade

Inside other components #

The button shows the hint after its label; the input, at the end of the box. Both use this tag, so their kbd takes a shortcut too, when it has a modifier: kbd="mod.k" shows "⌘K" or "Ctrl K", while kbd="/" or kbd="Ctrl K" is shown as written.

/
Blade

Sizes #

size sets the font size and padding, from xs to 3xl.

⌘K ⌘K ⌘K ⌘K ⌘K ⌘K
Blade

Shortcut combinations #

Several keys side by side, for a list of shortcuts.

Search
⌘ K
Save
⌘ S
Command palette
⇧ ⌘ P
Blade

Customization #

Classes and attributes go to the <kbd> element.

Esc Enter
Blade

Reference

tk:kbd

Prop Type Default Description
label string | slot null The key text, translated. The default slot takes its place.
size string md xs, sm, md, lg, xl, 2xl or 3xl. Sets the font size and padding.
variant string box text renders the text only, without background or padding.
shortcut string null A shortcut in Alpine's key modifier syntax (mod.k, ctrl.shift.p, alt.enter, slash), shown with the keys of the user's platform. mod is ⌘ on Apple platforms and Ctrl elsewhere. Takes the place of label and the slot. A label written this way with at least one modifier (mod, ctrl, cmd, super, meta, alt, shift) is read as a shortcut too.

Also accepts the element props (icon, prefix, suffix...).

Slots

Slot Description
default The key text, in place of label.

Customization

Classes and attributes go to the <kbd> element.

blade

Accessibility

A native <kbd>, which marks the text as keyboard input. It has pointer-events-none, so it never takes clicks from the button or item around it.

With shortcut, the keys of the other platform are hidden with display: none, so assistive technology reads only the ones shown: "⌘K" is read by VoiceOver as "command K".

Behavior notes

  • With no label, no slot content and no shortcut, nothing is rendered.
  • The server cannot know the user's platform, so a shortcut renders the keys of both and shows the ones its guess picks: Apple when the request's Sec-CH-UA-Platform header or user agent names macOS or iOS, the others otherwise. The script then marks the real platform on <html> (data-tallkit-platform="apple" or "other"), and CSS shows the matching keys. When the guess is right, which is the usual case, nothing moves; it only changes on a page cached for another platform or a browser that hides its own.
  • Keys are named as each platform writes them: Apple joins ⌃ ⌥ ⇧ ⌘ and the key with no space ("⌥⇧N", "⌘↩"), the others write Ctrl, Alt, Shift, Meta and the key with spaces ("Alt Shift N", "Ctrl Enter"). slash, comma, period, minus, equal, the arrows, escape (Esc) and space have their own names; a single letter is upper-cased.