component
Kbd
A key on the keyboard, written in the text. A small grey cap with the key's name in mono.
Defaultimport { Kbd } from 'rost/components/kbd/Kbd'
Press <Kbd aria-label="Command">⌘</Kbd> + <Kbd>K</Kbd> to search. src/components/kbd/Kbd.tsx
import type { HTMLAttributes, ReactNode } from 'react'
import './kbd.css'
export interface KbdProps extends HTMLAttributes<HTMLElement> {
/** The key, as it's printed on the keyboard. */
readonly children: ReactNode
}
/** A key on the keyboard, in the text. Built from contracts/kbd.contract.yaml. */
export function Kbd({ className, children, ...rest }: KbdProps) {
return <kbd className={['rost-kbd', className].filter(Boolean).join(' ')} {...rest}>{children}</kbd>
}
The source for everything on this page: contracts/kbd.contract.yaml (opens in a new tab). The CSS, the docs and the checks in each app are built from it.
# yaml-language-server: $schema=../schema/component-contract.schema.json
schemaVersion: 2
id: kbd
name: Kbd
kind: component
status: review
summary: A key on the keyboard, written in the text. A small grey cap with the key's name in mono.
category: display
related: [ code, text ]
source:
tool: figma
fileKey: 1Zy0wiWKXQAvsfDBX3KR0d
nodeId: "742:25"
url: https://www.figma.com/design/1Zy0wiWKXQAvsfDBX3KR0d/UI-Kit-v01?node-id=742-25
extractedAt: "2026-11-16"
extractedBy: hand
frozenAt: "2026-11-16"
props:
children: { type: slot, required: true, notes: "The key: Esc, Enter, ⌘, K. One Kbd per key; put a plus between them in the text." }
elements:
root:
notes: "A `<kbd>`. 20px tall, at least as wide, so a single letter is a square."
styles:
display: { value: inline-flex, assert: false }
align-items: { value: center }
justify-content: { value: center }
vertical-align: { value: middle, assert: false }
min-width: { token: spacing/size/xsmall, value: 20px }
height: { token: spacing/size/xsmall, value: 20px }
padding-left: { token: spacing/gap/xsmall, value: 6px }
padding-right: { token: spacing/gap/xsmall, value: 6px }
border-radius: { token: spacing/radius/xsmall, value: 4px }
background: { token: kbd/background, value: "#171717" }
outline-style: { value: solid, assert: false }
outline-width: { token: spacing/outline/small, value: 1px }
outline-offset: { value: "calc(-1 * var(--spacing-outline-small))", untokenised: "Composed from a token: the edge sits inside." }
outline-color: { token: kbd/edge, value: "#3a3a3a" }
font-family: { value: "'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace", notes: "Code's mono. Rost has no mono family token yet." }
font-weight: { token: typography/label/font-weight/medium, value: "500" }
font-size: { token: typography/label/font-size, value: 12px }
line-height: { token: typography/label/line-height, value: 14px }
color: { token: kbd/label, value: "#d3d9d5" }
guidance:
status: proposed
use:
- title: Shortcuts
text: "Telling someone which keys do something: Press ⌘ + K to search."
avoid:
- title: Code
text: "Something you type, like a command or a value. That's **Code**."
behaviour: "A cap per key. It doesn't press: it's text."
accessibility:
element: "`<kbd>`, which screen readers know as keyboard input."
name: "The key's name. Write symbols out in an `aria-label` when they'd be read oddly (⌘ is \"Command\")."
colour: "The key's name is 11:1 on its cap in dark."
content: "The key as it's printed on the keyboard: Esc, Enter, Tab, ⌘."
Install
npx github:Runceanu/rost add kbd It lands in src/rost/kbd/, with what it needs and its contract. Install has the rest.
When to use
Shortcuts
Telling someone which keys do something: Press ⌘ + K to search.
When not to use
Code
Something you type, like a command or a value. That's Code.
Behaviour
A cap per key. It doesn't press: it's text.
Accessibility
- Element
<kbd>, which screen readers know as keyboard input. - Name
The key's name. Write symbols out in an
aria-labelwhen they'd be read oddly (⌘ is "Command"). - Colour
The key's name is 11:1 on its cap in dark.
Content
The key as it's printed on the keyboard: Esc, Enter, Tab, ⌘.
Props
| Prop | Type | Values | Default |
|---|---|---|---|
children | slot | | |
Values
Straight from the contract. Each value sits next to its token, because six tokens here all come out as #3a3a3a and the colour alone can't tell you which one is right.
Never changes
root
-
min-width20pxspacing/size/xsmall -
height20pxspacing/size/xsmall -
padding-left6pxspacing/gap/xsmall -
padding-right6pxspacing/gap/xsmall -
border-radius4pxspacing/radius/xsmall -
background#171717kbd/background -
outline-width1pxspacing/outline/small -
outline-offsetcalc(-1 * var(--spacing-outline-small))on purpose: Composed from a token: the edge sits inside. -
outline-color#3a3a3akbd/edge -
font-family'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospaceno token yet -
font-weight500typography/label/font-weight/medium -
font-size12pxtypography/label/font-size -
line-height14pxtypography/label/line-height -
color#d3d9d5kbd/label
displayinline-flex · align-itemscenter · justify-contentcenter · vertical-alignmiddle · outline-stylesolid