Keys and shortcuts
Single keys inline, and KbdGroup for a combination. Each key is its own drawing, so no two caps are the same.
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.
npx shadcn@latest add @wobko/kbdFirst time here? Add the registry to components.json first. How to install
Single keys inline, and KbdGroup for a combination. Each key is its own drawing, so no two caps are the same.
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).
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.
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.
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.
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.
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.
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.
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.
| Prop | Type | Default | Description |
|---|---|---|---|
| data-pressed | boolean | - | Draw the key as held down. Set it from your own key handlers to show what the user is pressing. |
| seed | string | number | - | Pins the hand: the same seed always draws the same keycap, also across remounts. Default: derived from useId(). |
The files the CLI copies into your project.
Loading the source