Kbd

Free

Keycaps as real keys in miniature, a face on a skirt, with the modifier and arrow keys drawn, that press down while you hold the keys they show.

npx shadcn@latest add https://pixilui.com/r/kbd.json

Preview

Caps press down while you hold their keys.
Size

When to use

Use it when

  • A shortcut in a sentence: "Press ⌘ K to search runs".
  • A shortcuts sheet, an action and its keys on each row.
  • Keys on a dark surface (tone="dark"); inside a tooltip this is automatic.

Use something else when

  • Menu shortcuts: menus keep plain-text shortcuts, like macOS menus.
  • A button's own shortcut chip: the button draws it.

Installation

Terminal
npx shadcn@latest add https://pixilui.com/r/kbd.json

Adds kbd.tsx, and installs clsx and tailwind-merge. The URL works in any app with a components.json, with no registry to add first.

Usage

example.tsx
import { Kbd } from "@/components/pixilui/kbd";

<Kbd keys={keys} />

md 20 tall for sentences and sheets, sm 18 for tooltips and dense rows; caps sit on the text's middle.

API reference

PropTypeDefault
keysRequiredstring | readonly string[]NONEThe shortcut: "⌘ K", "⌘K" or ["⌘", "K"]. Modifier and arrow keys are drawn.
size"md" | "sm"–md 20 tall (sentences and shortcut sheets, default); sm 18 (tooltips and dense rows).
tone"dark"–dark: on a dark surface, the key's front lighter than the surface and darker than its face. Inside a tooltip this is automatic.
heldreadonly string[]–Keys shown held, for a still copy (a shortcut sheet, a screenshot). Live holding needs nothing: caps press while their keys are held.
stillboolean–Turn off the live press (a cap that should never move).

Also takes every native <span> attribute, and a ref.

Keyboard

TabNever takes focus: keycaps describe keys, they are not controls.

Accessibility

  • Each key is a kbd element; drawn keys keep their character in visually hidden text, so readers say "command", not nothing.
  • Pressing is a state shown while the real key is held, never the only way to learn a shortcut.

Motion

  • None by design: a held key travels down into its skirt as a state, with no transition, since keyboard actions never animate.
TooltipOne tooltip travels along a row, its labels sliding past inside it.
ButtonThe button brightens on hover, dips to .96 when pressed, and shows pending and done.
AvatarEach person keeps one color, picked from their name.

PixilUI Pro opens soon. The first 20 licenses are $99.