skip to content
mpkcn

~/components/kbd

Kbd

A keyboard key badge with a thick bottom edge, for single keys or combos like Ctrl + K.

open command palette
Ctrl+K
show shortcuts
Shift+?
close
Esc
next / previous
j/k

press ? for help

Installation

terminal
npx mpkcn add kbd
deps:none beyond react· tested with react@19.3.0

Usage

tsx
import { Kbd } from "@/components/mpkcn/kbd";

export function SearchHint() {
  return (
    <p>
      Press <Kbd keys={["Ctrl", "K"]} /> to search.
    </p>
  );
}

Kbd is a plain server-friendly component: no state, no effects, no "use client".

Examples

Single key

EscEnter ↵

Combos and separators

An array renders one badge per key. separator changes what goes between them, for example / for alternatives or then for sequences.

Ctrl+Shift+Pj/kgtheng

Inline in small text

Use size="sm" inside captions and footers.

tsx
<p className="font-mpk-mono text-[11px] text-mpk-dim2">
  press <Kbd keys="?" size="sm" /> for shortcuts
</p>

Props

PropTypeDefaultDescription
keysstring | string[]—The key, or the keys of a combo, e.g. "K" or ["Ctrl", "K"]. Ignored when children is set.
childrenReact.ReactNode—Custom content for a single key. Takes precedence over keys.
separatorReact.ReactNode"+"Text shown between the keys of a combo.
size"sm" | "md""md""sm" for inline hints in small text, "md" for body text.
classNamestring—Extra classes for the outer element.

Accessibility

  • Renders the semantic <kbd> element. A combo is one outer <kbd> wrapping one <kbd> per key, as the HTML spec describes for key combinations.
  • The separator is real text, so a screen reader reads "Ctrl + K" rather than "Ctrl K".
  • It is not interactive and takes no focus. If you want the badge to trigger the shortcut on click, wrap it in a button with a label.