Skip to content
Statix Design System

Display

Kbd

Shows a key or shortcut, for example in a search field or a tooltip.

import * as Kbd from '@statix/ui/kbd';

Examples

Basic

Single keys and a group for a combination.

Esc Enter Ctrl K ⌘ Shift P
<script lang="ts">
	import * as Kbd from '@statix/ui/kbd';
</script>

<Kbd.Root>Esc</Kbd.Root>
<Kbd.Root>Enter</Kbd.Root>
<Kbd.Group>
	<Kbd.Root>Ctrl</Kbd.Root>
	<Kbd.Root>K</Kbd.Root>
</Kbd.Group>
<Kbd.Group>
	<Kbd.Root aria-label="Command">⌘</Kbd.Root>
	<Kbd.Root>Shift</Kbd.Root>
	<Kbd.Root>P</Kbd.Root>
</Kbd.Group>

In text

Inline in a sentence. The 24px height fits the 15px body line.

Press Esc to close the dialog, or CtrlEnter to send the message to support.

<script lang="ts">
	import * as Kbd from '@statix/ui/kbd';
</script>

<p class="text-ink-2">
	Press <Kbd.Root>Esc</Kbd.Root> to close the dialog, or
	<Kbd.Group><Kbd.Root>Ctrl</Kbd.Root><Kbd.Root>Enter</Kbd.Root></Kbd.Group> to send the message to support.
</p>

In a search field

A shortcut hint at the end of an input.

<script lang="ts">
	import * as Kbd from '@statix/ui/kbd';
	import SearchIcon from '@lucide/svelte/icons/search';
</script>

<label
	class="flex h-control-md w-full max-w-sm items-center gap-2 rounded-full border border-input bg-card px-4 focus-within:ring-3 focus-within:ring-ring/40"
>
	<SearchIcon class="size-4 text-muted-foreground" />
	<input
		class="min-w-0 flex-1 bg-transparent outline-none placeholder:text-muted-foreground"
		placeholder="Search domains and mailboxes"
		aria-label="Search domains and mailboxes"
	/>
	<Kbd.Group>
		<Kbd.Root>Ctrl</Kbd.Root>
		<Kbd.Root>K</Kbd.Root>
	</Kbd.Group>
</label>

Guidelines

Do

  • Write keys as they are printed: Ctrl, Shift, Enter, ⌘.

Don't

  • Don’t show shortcuts on touch-only screens.

Accessibility

  • Renders a native <kbd>, which screen readers announce as text.
  • Symbols like ⌘ are read inconsistently. Add an aria-label such as aria-label="Command" where it matters.

API reference

Kbd.Root

renders <kbd> and accepts its attributes
PropTypeDefault
ref bindHTMLElement | null

The rendered element.

–
class ClassValue

Merged with the base classes; yours win.

–
Data attributeMeaning
data-slot="kbd"Always present.

Kbd.Group

renders <kbd> and accepts its attributes

Wraps several keys with a 4px gap.

Data attributeMeaning
data-slot="kbd-group"Always present.