UI.MD

Kbd

A keycap for a key or shortcut: key hints under a command palette, or a shortcut inside a button label.

Installation

$
npx shadcn@latest add https://ui.mattdowney.com/r/kbd.json

Usage

import { Kbd, KbdGroup, KbdHint } from "@/components/ui/kbd"

Examples

Key hints

KbdHint pairs keys with the word for what they do and owns the 6px between them; pass an array for several keys, which sit 4px apart. Show hints to pointer devices only; a phone has no keys.

↑↓Navigate↵OpenEscClose

In a button

Put the cap after the label. Inside a Button its text and edge follow the label's own colour, a step quieter, so it belongs to every variant's fill.

API Reference

PropTypeDefaultDescription
childrenKbdReact.ReactNode-The key or keys, as glyphs: ⌘K, ↵, Esc. One cap per key in a hint row; one cap for a whole chord in a button.
keysKbdHintstring | string[]-One key, or several shown as separate caps in a KbdGroup.
childrenKbdHintReact.ReactNode-The word for what the keys do: Navigate, Open, Close.
childrenKbdGroupReact.ReactNode-Several Kbd caps, 4px apart, read as one hint. KbdHint builds this for you from an array.
childrenKbdReact.ReactNodeThe key or keys, as glyphs: ⌘K, ↵, Esc. One cap per key in a hint row; one cap for a whole chord in a button.
keysKbdHintstring | string[]One key, or several shown as separate caps in a KbdGroup.
childrenKbdHintReact.ReactNodeThe word for what the keys do: Navigate, Open, Close.
childrenKbdGroupReact.ReactNodeSeveral Kbd caps, 4px apart, read as one hint. KbdHint builds this for you from an array.