Display

Kbd

Shows a key or a shortcut, with the right symbols on Apple devices and the right names elsewhere.

Installation

npx sinaui add kbd

Examples

Shortcuts

mod is ⌘ on Apple devices and Ctrl elsewhere. Try pressing them: keys light up while held.

Search
Command+K
Save to reading list
Command+S
Next page
Right arrow
Previous page
Left arrow
Open in a new tab
Command+Return
Undo
Command+Z
Redo
Command+Shift+Z
<script lang="ts">
	import Kbd from '#lib/ui/Kbd.svelte';

	const shortcuts = [
		{ does: 'Search', keys: ['mod', 'K'] },
		{ does: 'Save to reading list', keys: ['mod', 'S'] },
		{ does: 'Next page', keys: ['right'] },
		{ does: 'Previous page', keys: ['left'] },
		{ does: 'Open in a new tab', keys: ['mod', 'enter'] },
		{ does: 'Undo', keys: ['mod', 'Z'] },
		{ does: 'Redo', keys: ['mod', 'shift', 'Z'] }
	];
</script>

<dl>
	{#each shortcuts as s (s.does)}
		<div class="row">
			<dt>{s.does}</dt>
			<dd><Kbd keys={s.keys} /></dd>
		</div>
	{/each}
</dl>

<style>
	dl {
		display: grid;
		gap: 0.25rem;
		inline-size: min(100%, 22rem);
		margin: 0;
	}
	.row {
		display: flex;
		align-items: center;
		justify-content: space-between;
		gap: 1rem;
		min-block-size: 2rem;
	}
	dd {
		margin: 0;
	}
</style>

In a sentence

Press Command+K to search the catalog, and Esc to close it.

<script lang="ts">
	import Kbd from '#lib/ui/Kbd.svelte';
</script>

<p>
	Press <Kbd keys={['mod', 'K']} /> to search the catalog, and <Kbd>Esc</Kbd> to close it.
</p>

<style>
	p {
		margin: 0;
	}
</style>

Props

PropTypeDefault
keysstring[]: mod, ctrl, shift, alt, enter, esc, backspace, tab, arrows (up…), or any key
childrenSnippet: a single key written out

Accessibility

  • Symbols are read by name: ⌘K is read “Command+K”, not “place of interest sign K”.
  • Only shows keys: it does not bind them. Add the shortcut yourself, and say so with aria-keyshortcuts on the control it triggers.
Introduction
Theming
Changelog
Button
Action button
Confirm button
Copy button
Hold to confirm
Split button
Calendar
Checkbox
Color picker
Combobox
Date picker
Date range picker
File drop
Form
Input
Mention input
Multi select
Number field
OTP input
Password input
Phone input
Radio cards
Radio group
Rich text editor
Search field
Segmented control
Select
Signature pad
Slider
Switch
Tag input
Upload
Wheel picker
Textarea
Time field
Toggle group
Toolbar
Alert dialog
Command palette
Context menu
Dialog
Drawer
Dropdown
Hover card
Popover
Tooltip
Announcement bar
Alert
Empty state
Meter
Progress
Rolling number
Skeleton
Spinner
Toast
Avatar
Avatar group
Badge
Card
Carousel
Chart
Chat
Code block
Data table
Folder
Kbd
Mind map
Resizable panels
Scroll area
Separator
Sortable
Table
Tag group
Virtual list
Audio player
Image
Image compare
Video
Visualizer
Breadcrumb
File tree
Menubar
Navigation menu
Pagination
Sidebar layout
Stepper
Tabs
Alarm clock
Clock
Dynamic island
Fluid orb
Hourglass
Stopwatch
Timer
AI chat
AI media
Auth
Board
Booking
Dashboard
File explorer
Messaging
Notifications
Settings
Team
Overview
Pricing
Agent chat
Calendar
Voice agent
Mail inbox
CMS
Blog
Marketing site
E-commerce
AI agents
SaaS landing page
SaaS app
Accordion
Dark theme
Light theme