Skip to main content

Kbd

Info:Content
75

A keycap for the keys in a shortcut.

keycap shortcut hotkey key keyboard key

Live demo

live · @xtyle/astro

Kbd

Chords

Ctrl

+

K
Ctrl

+

Shift

+

P

Sizes

Esc Enter Space

Tones

A tone tints the whole keycap for a primary-chord or status key.

K Enter Tab Del ?

Inline

Press / to search, or Esc to dismiss.

Kbd renders a single key as a physical keycap: a mono-faced label on a raised surface, the depth read from a heavier bottom edge rather than a drop shadow, so it sits cleanly inline in running text. It carries no layout of its own: set a few side by side in a Cluster to spell a chord (Ctrl + K).

Everything about its look is derived chrome: the surface, the edge, the radius all come from the same tokens the rest of the theme does, so a keycap matches the UI it documents. The size prop steps it with the surrounding type from sm to lg, and an optional tone tints the whole keycap (face, edge, and label) to any of the semantic roles or named hues for a primary-chord or status key.

When to use

How this component composes with the rest of the set.

Spell a chord by setting keys in a Cluster with a small gap: Ctrl + K.
Drop a Kbd inline in Text to name a shortcut mid-sentence. It sits on the baseline without breaking the line.
Pair shortcuts with their actions in a Table or a Stack of Clusters for a key map.

Props

2 props, straight from the manifest.

PropTypeDefaultBindingsDescription
size KbdSize
sm md lg
md
html svelte astro
The keycap size, stepping with the type scale: `sm`, `md`, or `lg`.
tone KbdTone
accent neutral danger success warn info accent-2 accent-3 accent-4 red orange yellow green blue purple brown pink cyan gray white black
html svelte astro
Tints the keycap face, edge, and label to a semantic role (accent, success, danger, …) or a named hue (red … black). Omit for the neutral keycap.

Appearance

Sizes

sm

.xtyle-kbd--sm

A compact keycap for dense inline hints.

md

default
.xtyle-kbd

The default keycap, sized with body text.

lg

.xtyle-kbd--lg

A prominent keycap for a featured shortcut.

Anatomy

The named parts that make up the component, with their selectors.

kbd

.xtyle-kbd

The keycap root: a raised surface with a weighted bottom edge.

--bg-2 --fg-1 --line-2 --border-thick --radius-sm --font-mono

Tokens & coverage

What the component consumes, checked live against what the algorithm produces.

Success:fully covered 75/75 consumed tokens produced default register: 299 tokens

Live coverage check against the xtyle-default register (derive(xtyleDefault, { anchors })coverComponent(manifest, register)). Every token this component consumes must be a key the algorithm produces.

--accent --accent-2 --accent-2-bg --accent-2-text --accent-3 --accent-3-bg --accent-3-text --accent-4 --accent-4-bg --accent-4-text --accent-bg --accent-text --bg-2 --black --black-bg --black-text --blue --blue-bg --blue-text --border-thick --border-thin --brown --brown-bg --brown-text --cyan --cyan-bg --cyan-text --danger --danger-bg --danger-text --fg-1 --font-mono --gray --gray-bg --gray-text --green --green-bg --green-text --info --info-bg --info-text --leading-tight --line-2 --neutral --neutral-bg --neutral-text --orange --orange-bg --orange-text --pink --pink-bg --pink-text --purple --purple-bg --purple-text --radius-sm --red --red-bg --red-text --success --success-bg --success-text --text-lg --text-sm --text-xs --warn --warn-bg --warn-text --weight-medium --white --white-bg --white-text --yellow --yellow-bg --yellow-text

Slots

default
html svelte astro

The key label: a glyph or short word like K, Esc, or Enter.

Accessibility

Renders the semantic <kbd> element, so assistive tech announces the content as keyboard input.
Keep the label the literal key name; the keycap styling is presentational and adds no meaning of its own.

Code

Keys and sizes

Single keys and a chord, shown across the three sizes.

<xtyle-kbd>Ctrl</xtyle-kbd>
<xtyle-kbd>K</xtyle-kbd>

<xtyle-kbd size="sm">Esc</xtyle-kbd>
<xtyle-kbd size="lg">Enter</xtyle-kbd>
<script lang="ts">
	import { Kbd } from "@xtyle/svelte";
</script>

<Kbd>Ctrl</Kbd>
<Kbd>K</Kbd>
---
import Kbd from "@xtyle/astro/Kbd.astro";
---

<Kbd>Ctrl</Kbd>
<Kbd>K</Kbd>

Toned keycaps

A tone tints the whole keycap for a primary-chord or status key.

<xtyle-kbd tone="accent"></xtyle-kbd>
<xtyle-kbd tone="success">Enter</xtyle-kbd>
<xtyle-kbd tone="danger">Del</xtyle-kbd>
<script lang="ts">
	import { Kbd } from "@xtyle/svelte";
</script>

<Kbd tone="accent"></Kbd>
<Kbd tone="danger">Del</Kbd>
---
import Kbd from "@xtyle/astro/Kbd.astro";
---

<Kbd tone="accent"></Kbd>
<Kbd tone="danger">Del</Kbd>