Data Display & Media
Kbd
A keyboard key, or a shortcut spelled as one key per press, shown with the right modifier for the reader's platform.
Preview
Section titled “Preview”Search with
Open the command list with
Close with
<p>
Search with
<nana-kbd keys="mod+k"></nana-kbd>
</p>
<p>
Open the command list with
<nana-kbd keys="mod+shift+p"></nana-kbd>
</p>
<p>
Close with
<nana-kbd>Esc</nana-kbd>
</p> Search with ControlK
Open the command list with ControlShiftP
Close with Esc, or press ? for help
<script lang="ts">
import { NanaKbd } from '$lib/components/ui/kbd';
</script>
<div class="flex flex-col items-start gap-3 text-sm text-foreground-muted">
<p>Search with <NanaKbd keys="mod+k" /></p>
<p>Open the command list with <NanaKbd keys="mod+shift+p" /></p>
<p>Close with <NanaKbd>Esc</NanaKbd>, or press <NanaKbd size="sm">?</NanaKbd> for help</p>
</div> Installation
Section titled “Installation”Install the package for a versioned dependency:
npm install @nana-tec/ui-componentsOr copy the source in and own it:
npx @nana-tec/ui add kbd --framework web-componentsnpx @nana-tec/ui add kbd --framework svelteLands in src/lib/components/ui/kbd/ as NanaKbd.svelte, styled with Tailwind classes that
resolve to the design tokens. Requires Tailwind v4.
Import
Section titled “Import”
Import the autoloader once, in your app's entry point. Every <nana-*> tag then works anywhere, and
each component downloads only the first time a page uses it:
import "@nana-tec/ui-components/autoloader";import "@nana-tec/ui-components/theme";The second line gives every component the Nana look and the design tokens behind it. Leave it out to style the components entirely yourself.
Import a component directly when it must be ready at once: on screen at first paint, or when you call its methods straight away. The two mix freely:
import "@nana-tec/ui-components/kbd";
Copied in with npx @nana-tec/ui add kbd? Import your project's own
@/lib/nana-ui/autoloader.js once instead; the CLI keeps it up to date.
<script lang="ts"> import { NanaKbd } from '$lib/components/ui/kbd';</script>
<NanaKbd keys="mod+k" /><NanaKbd>Esc</NanaKbd>Shortcuts
Section titled “Shortcuts”Set keys to a shortcut written with + between the keys. Each key is drawn on its own,
inside one <kbd> for the whole combination, which is how HTML marks up a key combination.
mod is the main modifier: ⌘ on Apple devices and Ctrl elsewhere, so
one shortcut reads correctly on both. On Apple devices ctrl, alt, shift, enter,
backspace and tab show their symbols too.
| Write | Apple | Elsewhere |
|---|---|---|
mod+k | ⌘ K | Ctrl K |
mod+shift+p | ⌘ ⇧ P | Ctrl Shift P |
alt+enter | ⌥ ↵ | Alt Enter |
esc | Esc | Esc |
Any other key is shown as written, with its first letter capitalised.
Single keys
Section titled “Single keys”Without keys, the content is shown as one key.
<nana-kbd>Esc</nana-kbd><nana-kbd size="sm">?</nana-kbd><NanaKbd>Esc</NanaKbd><NanaKbd size="sm">?</NanaKbd>Accessibility
Section titled “Accessibility”A symbol is hidden from screen readers and followed by the key’s name, so ⌘ is read as “Command” rather than as an unnamed character. Kbd only shows a shortcut; the shortcut itself is up to your app.
Properties
| Property | Attribute | Type | Default | Description |
|---|---|---|---|---|
keys | keys | string | '' | A shortcut with + between keys, such as mod+k. mod is ⌘ on Apple devices and Ctrl elsewhere. Without it, the content is shown as one key. |
size | size | KbdSize | 'md' | Size preset. |
Slots
| Slot | Description |
|---|---|
(default) | The key's text, used when keys is not set |
CSS parts
| Part | Description |
|---|---|
::part(keys) | The combination around the keys |
::part(key) | Each key |
CSS custom properties
| Property | Description |
|---|---|
--nana-kbd-bg | Key background |
--nana-kbd-border | Key border and bottom edge |
--nana-kbd-color | Key text colour |
NanaKbd
| Prop | Type | Default |
|---|---|---|
size | KbdSize | 'md' |
keys | string | |
children | Snippet |
Also accepts Omit<HTMLAttributes<HTMLElement>, 'class'>.