Kbd
A key on the keyboard, or a shortcut made of several keys. Same markup and props in every style: switch the style in the header to see it change.
Keys
Single keys, including the arrows.
<kbd class="vin-kbd">Esc</kbd>
<kbd class="vin-kbd">Tab</kbd>
<kbd class="vin-kbd">Enter</kbd>
<kbd class="vin-kbd">Shift</kbd>
<kbd class="vin-kbd">↑</kbd>
<kbd class="vin-kbd">↓</kbd>
<kbd class="vin-kbd">←</kbd>
<kbd class="vin-kbd">→</kbd>import { Kbd } from "@/components/vin/kbd";
export function KbdKeys() {
return (
<>
<Kbd>Esc</Kbd>
<Kbd>Tab</Kbd>
<Kbd>Enter</Kbd>
<Kbd>Shift</Kbd>
<Kbd>↑</Kbd>
<Kbd>↓</Kbd>
<Kbd>←</Kbd>
<Kbd>→</Kbd>
</>
);
}The Vue version renders the same markup as the HTML tab, so it looks and works the same.
<script setup lang="ts">
import Kbd from "@/components/vin/kbd.vue";
</script>
<template>
<Kbd>Esc</Kbd>
<Kbd>Tab</Kbd>
<Kbd>Enter</Kbd>
<Kbd>Shift</Kbd>
<Kbd>↑</Kbd>
<Kbd>↓</Kbd>
<Kbd>←</Kbd>
<Kbd>→</Kbd>
</template>The Svelte version renders the same markup as the HTML tab, so it looks and works the same.
<script lang="ts">
import Kbd from "$lib/components/vin/kbd.svelte";
</script>
<Kbd>Esc</Kbd>
<Kbd>Tab</Kbd>
<Kbd>Enter</Kbd>
<Kbd>Shift</Kbd>
<Kbd>↑</Kbd>
<Kbd>↓</Kbd>
<Kbd>←</Kbd>
<Kbd>→</Kbd>Shortcuts
Group keys for a shortcut. Mac shortcuts usually go without the plus; the others read better with it.
<kbd class="vin-kbd-group"><kbd class="vin-kbd">⌘</kbd><kbd class="vin-kbd">K</kbd></kbd>
<kbd class="vin-kbd-group"><kbd class="vin-kbd">⌘</kbd><kbd class="vin-kbd">⇧</kbd><kbd class="vin-kbd">P</kbd></kbd>
<kbd class="vin-kbd-group"><kbd class="vin-kbd">Ctrl</kbd>+<kbd class="vin-kbd">Shift</kbd>+<kbd class="vin-kbd">P</kbd></kbd>import { Kbd, KbdGroup } from "@/components/vin/kbd";
export function KbdShortcuts() {
return (
<>
<KbdGroup><Kbd>⌘</Kbd><Kbd>K</Kbd></KbdGroup>
<KbdGroup><Kbd>⌘</Kbd><Kbd>⇧</Kbd><Kbd>P</Kbd></KbdGroup>
<KbdGroup><Kbd>Ctrl</Kbd>+<Kbd>Shift</Kbd>+<Kbd>P</Kbd></KbdGroup>
</>
);
}The Vue version renders the same markup as the HTML tab, so it looks and works the same.
<script setup lang="ts">
import Kbd, { KbdGroup } from "@/components/vin/kbd.vue";
</script>
<template>
<KbdGroup><Kbd>⌘</Kbd><Kbd>K</Kbd></KbdGroup>
<KbdGroup><Kbd>⌘</Kbd><Kbd>⇧</Kbd><Kbd>P</Kbd></KbdGroup>
<KbdGroup><Kbd>Ctrl</Kbd>+<Kbd>Shift</Kbd>+<Kbd>P</Kbd></KbdGroup>
</template>The Svelte version renders the same markup as the HTML tab, so it looks and works the same.
<script lang="ts">
import Kbd from "$lib/components/vin/kbd.svelte";
import KbdGroup from "$lib/components/vin/kbd-group.svelte";
</script>
<KbdGroup><Kbd>⌘</Kbd><Kbd>K</Kbd></KbdGroup>
<KbdGroup><Kbd>⌘</Kbd><Kbd>⇧</Kbd><Kbd>P</Kbd></KbdGroup>
<KbdGroup><Kbd>Ctrl</Kbd>+<Kbd>Shift</Kbd>+<Kbd>P</Kbd></KbdGroup>In context
In a button and at the end of a search field, the key takes the colour around it.
<button type="button" class="vin-btn vin-btn--secondary">
Save
<kbd class="vin-kbd-group"><kbd class="vin-kbd">⌘</kbd><kbd class="vin-kbd">S</kbd></kbd>
</button>
<button type="button" class="vin-btn">
Run
<kbd class="vin-kbd">↵</kbd>
</button>
<div class="vin-input vin-input-group" style="width: 100%; max-width: 280px">
<span class="vin-input-group__addon"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="11" cy="11" r="7"/><path d="m20 20-3.5-3.5"/></svg></span>
<input class="vin-input-group__input" type="search" placeholder="Search" aria-label="Search">
<span class="vin-input-group__addon"><kbd class="vin-kbd-group"><kbd class="vin-kbd">⌘</kbd><kbd class="vin-kbd">K</kbd></kbd></span>
</div>import { Kbd, KbdGroup } from "@/components/vin/kbd";
import { Button } from "@/components/vin/button";
import { InputGroup } from "@/components/vin/input-group";
export function KbdInContext() {
return (
<>
<Button variant="secondary">
Save
<KbdGroup><Kbd>⌘</Kbd><Kbd>S</Kbd></KbdGroup>
</Button>
<Button>
Run
<Kbd>↵</Kbd>
</Button>
<InputGroup
style={{ width: "100%", maxWidth: 280 }}
type="search"
placeholder="Search"
aria-label="Search"
start={<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><circle cx="11" cy="11" r="7" /><path d="m20 20-3.5-3.5" /></svg>}
end={<KbdGroup><Kbd>⌘</Kbd><Kbd>K</Kbd></KbdGroup>}
/>
</>
);
}The Vue version renders the same markup as the HTML tab, so it looks and works the same.
<script setup lang="ts">
import Kbd, { KbdGroup } from "@/components/vin/kbd.vue";
import Button from "@/components/vin/button.vue";
import InputGroup from "@/components/vin/input-group.vue";
</script>
<template>
<Button variant="secondary">
Save
<KbdGroup><Kbd>⌘</Kbd><Kbd>S</Kbd></KbdGroup>
</Button>
<Button>
Run
<Kbd>↵</Kbd>
</Button>
<InputGroup style="width: 100%; max-width: 280px" type="search" placeholder="Search" aria-label="Search">
<template #start><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="11" cy="11" r="7" /><path d="m20 20-3.5-3.5" /></svg></template>
<template #end><KbdGroup><Kbd>⌘</Kbd><Kbd>K</Kbd></KbdGroup></template>
</InputGroup>
</template>The Svelte version renders the same markup as the HTML tab, so it looks and works the same.
<script lang="ts">
import Kbd from "$lib/components/vin/kbd.svelte";
import KbdGroup from "$lib/components/vin/kbd-group.svelte";
import Button from "$lib/components/vin/button.svelte";
import InputGroup from "$lib/components/vin/input-group.svelte";
</script>
<Button variant="secondary">
Save
<KbdGroup><Kbd>⌘</Kbd><Kbd>S</Kbd></KbdGroup>
</Button>
<Button>
Run
<Kbd>↵</Kbd>
</Button>
<InputGroup style="width: 100%; max-width: 280px" type="search" placeholder="Search" aria-label="Search">
{#snippet start()}<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="11" cy="11" r="7" /><path d="m20 20-3.5-3.5" /></svg>{/snippet}
{#snippet end()}<KbdGroup><Kbd>⌘</Kbd><Kbd>K</Kbd></KbdGroup>{/snippet}
</InputGroup>Installation
React, Vue and Svelte: add the component to your project with the CLI. It reads your framework from vin.json and also copies any component this one needs. Then import it:
npx @vinish/ui add kbdimport { Kbd, KbdGroup } from "@/components/vin/kbd";import Kbd, { KbdGroup } from "@/components/vin/kbd.vue";import Kbd from "$lib/components/vin/kbd.svelte";
import KbdGroup from "$lib/components/vin/kbd-group.svelte";The import paths assume the default folders: @/components/vin (React and Vue, with the usual @ → src alias) and $lib/components/vin (SvelteKit). Use your own if you chose another folder in init. How the Vue and Svelte versions pass values and content is in Frameworks.
Plain HTML: the classes come with the style's stylesheet. It needs no JavaScript.
API
From spec/kbd.json, which every framework version is tested against.
| Prop | Values | Default | In HTML |
|---|---|---|---|
KbdOne key. | children | — | <kbd class="vin-kbd"> |
KbdGroupA shortcut: several Kbd inside. | children | — | <kbd class="vin-kbd-group"> |
Parts
| React, Vue, Svelte | HTML classes |
|---|---|
<Kbd><KbdGroup> | .vin-kbd.vin-kbd-group |
Accessibility
- Uses the <kbd> element, which means keyboard input; a shortcut is a <kbd> holding one <kbd> per key, as the HTML spec suggests.
- Screen readers say symbols like ⌘ and ⇧ in different ways. For an important shortcut, also write it in words nearby ("Command K"), or show Ctrl on Windows.
- The shortcut must work as well: Kbd only shows it.
Customize
Saved in this browser. Style and accent are in the header.