Components

Kbd

A keyboard key, drawn in pencil as a little keycap with a shaded thickness that presses flat under your finger. Used inline, in groups, in tooltips and in menus.

Install

terminal
npx shadcn@latest add @wobko/kbd

First time here? Add the registry to components.json first. How to install

Examples

Keys and shortcuts

Single keys inline, and KbdGroup for a combination. Each key is its own drawing, so no two caps are the same.

Press the keys

data-pressed shows a key as held. Type on your keyboard: the caps you press sink onto their base (or press and hold one with the pointer).

A shortcut sheet

Kbd next to the things it triggers: a search field that says how to reach it, and a cheat sheet in a card. The muted keys stay quiet; the words next to them do the talking.

Modifier keys

shadcn's `kbd-demo`: a KbdGroup of the four Mac modifiers, and a Ctrl + B written with a plain `+` between two keys. Each cap is drawn on its own, so no two are quite alike.

In a tooltip

shadcn's `kbd-tooltip`: hover or focus a button to see its shortcut written on the tip. Inside a tooltip the keycaps take the tip's own ink. Radix wants a `TooltipProvider` above every tooltip (shadcn's docs site has one at the root), so the example brings its own.

In an input group

shadcn's `kbd-input-group`: a search box with the shortcut that focuses it written at the end. Two keycaps in one inline-end addon.

In a button

shadcn's `kbd-button`: a keycap at the end of a button's label. The button takes a little less padding on that side (`pe-2`) so the cap sits close to the edge.

Group in a sentence

shadcn's `kbd-group`: a KbdGroup sits inline in running text. Each Kbd here holds a whole chord ("Ctrl + B") as one cap; compare with the separate keys in the first example.

API reference

Kbd

A <kbd> element with a pencil keycap behind its label. (Unlike shadcn's it is not pointer-events-none, so that pressing it can sink the cap.) The label is real text in the hand font; the drawing is measured from the element and uses the text color, so it is graphite on paper and takes its color from whatever it sits in. While the pointer is down on it, or while you set data-pressed, the thickness disappears and the cap sinks onto its base.

PropTypeDefaultDescription
data-pressedboolean-Draw the key as held down. Set it from your own key handlers to show what the user is pressing.
seedstring | number-Pins the hand: the same seed always draws the same keycap, also across remounts. Default: derived from useId().

Accessibility

  • Kbd is the semantic <kbd> element: screen readers read the text as it is written. Write words for modifier keys when the symbol would be read unhelpfully ("Ctrl" rather than an icon), or give an icon-only key an Icon with a label (aria-label is not allowed on a bare <kbd>).
  • Decorative by nature: it is not focusable and has no role. The press animation is pointer feedback only; nothing depends on it.
  • Muted graphite on paper is 8.9:1. Inside a Tooltip or a menu the label and the drawing take that surface's text color.
  • Calm density draws a plain pencil box without the thickness; reduced motion removes the press transition.

Source

The files the CLI copies into your project.

Loading the source