Skip to main content

Kbd

A square, centered keyboard "key" chip for rendering shortcut hints — K, ⌘, ⌃, Enter. Renders a native <kbd> element so screen readers announce it as keyboard input. Sized so letters and modifier symbols share a consistent visual height, width, and baseline.

When to use

  • Documenting keyboard shortcuts in copy or tooltips.
  • Inside menu items and command palettes alongside the action label.
  • Inline with prose: "Press K to open search."

When not to use

  • For arbitrary monospace text — use Code.
  • For chord-style multi-key shortcuts as a single chip — render multiple <Kbd> elements separated by + text instead.
KCommandControlShiftOption
import { Kbd } from "@ngrok/mantle/kbd"; <div className="flex items-center gap-2">	<Kbd>K</Kbd>	<Kbd>		<span className="sr-only">Command</span>		<span aria-hidden>⌘</span>	</Kbd>	<Kbd>		<span className="sr-only">Control</span>		<span aria-hidden>⌃</span>	</Kbd>	<Kbd>		<span className="sr-only">Shift</span>		<span aria-hidden>⇧</span>	</Kbd>	<Kbd>		<span className="sr-only">Option</span>		<span aria-hidden>⌥</span>	</Kbd></div>;

Keyboard shortcuts

Combine multiple Kbd components to display keyboard shortcuts.

Command+K
Control+Shift+P
import { Kbd } from "@ngrok/mantle/kbd"; <div className="flex flex-col gap-4">	<div className="flex items-center gap-2">		<Kbd>			<span className="sr-only">Command</span>			<span aria-hidden>⌘</span>		</Kbd>		<span>+</span>		<Kbd>K</Kbd>	</div>	<div className="flex items-center gap-2">		<Kbd>			<span className="sr-only">Control</span>			<span aria-hidden>⌃</span>		</Kbd>		<span>+</span>		<Kbd>			<span className="sr-only">Shift</span>			<span aria-hidden>⇧</span>		</Kbd>		<span>+</span>		<Kbd>P</Kbd>	</div></div>;

Accessibility

Screen readers do not announce symbol-only glyphs (⌘, ⌃, ↵) meaningfully. Put a visually hidden label inside the <Kbd> and mark the visible glyph aria-hidden. Do not set aria-label on the <Kbd>: <kbd> has the generic role, which prohibits naming, so a screen reader does not read the label reliably.

Command+K
import { Kbd } from "@ngrok/mantle/kbd"; <div className="flex items-center gap-2">	<Kbd>		<span className="sr-only">Command</span>		<span aria-hidden>⌘</span>	</Kbd>	<span>+</span>	<Kbd>K</Kbd></div>;

Translation

The <kbd> element always carries translate="no", so a browser translation engine skips the subtree. A translated shortcut names a key the reader's keyboard does not have.

Kbd omits the translate prop from its type, so no call site can turn the guard off. A key is never translatable, unlike Code, which also styles terms that are not code and therefore takes the override. See that page for the second reason the attribute matters: a translation engine that rewrites the text nodes React holds can also break the render, and Browser translation for the mechanism in full.

API Reference

Kbd

The Kbd accepts the following props in addition to the standard HTML kbd attributes, except translate.

PropTypeDefaultDescription
childrenReactNodeThe keyboard key or symbol to display (e.g., "K", "⌘", "⌃").
className?stringAdditional CSS classes to apply to the kbd element.