Skip to content

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.

Esc Tab Enter Shift ↑ ↓ ← →
kbd-keys.html
<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>

Shortcuts

Group keys for a shortcut. Mac shortcuts usually go without the plus; the others read better with it.

⌘K ⌘⇧P Ctrl+Shift+P
kbd-shortcuts.html
<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>

In context

In a button and at the end of a search field, the key takes the colour around it.

⌘K
kbd-in-context.html
<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>

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:

Terminal
npx @vinish/ui add kbd
React
import { Kbd, KbdGroup } from "@/components/vin/kbd";
Vue
import Kbd, { KbdGroup } from "@/components/vin/kbd.vue";
Svelte
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.

PropValuesDefaultIn HTML
Kbd
One key.
children—<kbd class="vin-kbd">
KbdGroup
A shortcut: several Kbd inside.
children—<kbd class="vin-kbd-group">

Parts

React, Vue, SvelteHTML 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.