Skip to content

Kbd

Keyboard key indicator rendered as an inline kbd element with terminal styling.

Info:

size="sm" renders 10px type — a dense desktop-legend size. On mobile/touch surfaces keep the default size="md".

Preview

Installation

$pnpm exec dgadd add ui/kbd
[Installs to]src/components/ui/kbd[Item]ui/kbd

dgadd is not public on npm yet. Until the first release, pack @diffgazer/add from the repository and install that tarball into this app, which is what puts dgadd on pnpm exec.

UI components require Tailwind CSS v4. Local copy mode imports src/styles/styles.css; package mode uses @diffgazer/ui CSS once packages are available.

Usage

tsx
import { Kbd } from "@/components/ui/kbd";export default function KbdDefault() {  return (    <div className="flex flex-wrap items-center gap-3">      <Kbd>Esc</Kbd>      <Kbd>Enter</Kbd>      <Kbd>Shift</Kbd>      <Kbd>Tab</Kbd>      <Kbd>Ctrl</Kbd>    </div>  );}

Examples

Sizes

Preview

Inline

Preview

Group

Preview

API Reference

Kbd

NameTypeDefaultDescription
size"sm" | "md""md"Padding and font-size token applied to the kbd glyph.
variant"default" | "inverse""default"Surface the cap is painted for: default (page background) or inverse (a --foreground bar).
childrenReactNodeKey glyph or short label rendered inside the <kbd> element.

KbdGroup

NameTypeDefaultDescription
childrenReactNodeSequence of Kbd children rendered inline with a small gap.

Accessibility

Notes

Size Variants

Available in sm and md sizes (defaults to md). Renders inline, designed for use inside text.

Terminal Styling

Rendered with a hairline border and a translucent --foreground fill so the key cap carries the same inline weight in light and dark palettes.

Inverse surfaces

Use `variant="inverse"` for caps on a bar painted in --foreground (shortcut legends, app footers). It mirrors the same border/fill recipe against --background, so the cap keeps its weight instead of disappearing into the inverted bar.

Chord Grammar

Two grammars are supported and should not be mixed on one surface: platform chords place modifier glyphs adjacent with no separator (Command K), spelled-out chords use a dimmed + between caps (Ctrl + Shift + P). Wrap either in KbdGroup and give the group an aria-label so assistive tech announces the whole shortcut.

Source

Install via CLI: pnpm exec dgadd add ui/kbd.

Highlighted source loads after this disclosure opens. Browse the source repository.