Skip to content

Kbd

Render keyboard shortcuts as styled key caps. Parses +-separated combinations, maps key names to symbols (⌘, ⇧, ⌥), and swaps modifiers per platform.

import { Kbd } from "@nu-appdev/northwestern-starlight-theme/components";

Pass key combinations as children, separated by +.

Copy: CCtrlC · Paste: VCtrlV · Undo: ZCtrlZ

<Kbd>Ctrl+C</Kbd>
<Kbd>Ctrl+V</Kbd>
<Kbd>Ctrl+Z</Kbd>

Use Mod, Command, Ctrl, Alt, or Option in the key string. Platform is detected automatically — Mac users see ⌘, Windows/Linux users see Ctrl.

Open search: KCtrlK · Command palette: PCtrlP · Inspector: IAltI

<Kbd>Mod+K</Kbd>
<Kbd>Mod+Shift+P</Kbd>
<Kbd>Alt+Shift+I</Kbd>

Key names map to standard symbols. Unrecognized names render as-is (A, F12). Modifier symbols change per platform.

Modifiers
#Command / Cmd / MetaCtrl
#Control / CtrlCtrl
#Option / AltAlt
#ShiftShift
#ModCtrl
Actions
#Enter / Return
#Backspace
#Delete
#Escape / EscEsc
#Tab
#Space
#CapsLock
Navigation
#Up / Down / Left / Right↑ ↓ ← →
#PageUp / PageDown⇞ ⇟
#Home / End↖ ↘

The tip prop wraps the shortcut in a <Tooltip/>, showing a description on hover.

PCtrlPOpen command palette     SCtrlSSave file

<Kbd tip="Open command palette">Mod+Shift+P</Kbd>
<Kbd tip="Save file">Mod+S</Kbd>

Use the keys array to specify each key explicitly.

ICtrlI     KCtrlK

<Kbd keys={["Ctrl", "Shift", "I"]} />
<Kbd keys={["Command", "K"]} />

Implementation: Kbd.astro

#childrenstring

Key combination string. Parsed on + into individual keys. Key names are mapped to symbols.

#keysstring[]

Explicit array of key names. Overrides children parsing.

#tipstring

Description shown on hover via Tooltip.