Skip to content
v1.0.3

Kbd

A keyboard key cap for shortcut hints. Pass a single key, or a keys array for a combination. Common tokens are prettified: mod/cmd → ⌘, shift → ⇧, alt/option → ⌥, ctrl → ⌃, enter → ↵, esc → Esc, arrows → ↑↓←→.

bash
jlds add kbd

Usage

html
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/jarooda/jlds@main/registry/css/index.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/jarooda/jlds@main/registry/css/kbd.css">

<kbd class="jl-kbd">K</kbd>
vue
<script setup lang="ts">
import { Kbd } from "@/components/ui/kbd"
</script>

<template>
  <Kbd>K</Kbd>
</template>
tsx
import { Kbd } from "@/components/ui/kbd"

<Kbd>K</Kbd>

Combinations

Pass keys to render a combination with + separators. Tokens are prettified automatically.

html
<span class="jl-kbd-group">
  <kbd class="jl-kbd">⌘</kbd>
  <span class="jl-kbd-group__plus" aria-hidden="true">+</span>
  <kbd class="jl-kbd">K</kbd>
</span>
vue
<template>
  <Kbd :keys="['mod', 'k']" />
  <Kbd :keys="['shift', 'enter']" />
</template>
tsx
<Kbd keys={["mod", "k"]} />
<Kbd keys={["shift", "enter"]} />

Sizes

md (default) and sm.

html
<kbd class="jl-kbd jl-kbd--sm">Esc</kbd>
<kbd class="jl-kbd">Esc</kbd>
vue
<template>
  <Kbd size="sm">Esc</Kbd>
  <Kbd size="md">Esc</Kbd>
</template>
tsx
<Kbd size="sm">Esc</Kbd>
<Kbd size="md">Esc</Kbd>

Props

React

Kbd extends React.HTMLAttributes<HTMLElement>.

PropTypeDefaultDescription
keysstring[]Key combination, rendered with + between caps
size"sm" | "md""md"Cap size
childrenReact.ReactNodeA single key when keys is not used

Vue

PropTypeDefaultDescription
keysstring[]Key combination
size"sm" | "md""md"Cap size

Slots: default — a single key when keys is not used.

CSS classes (HTML)

ClassPurpose
.jl-kbdBase key cap — always required
.jl-kbd--smSmaller cap
.jl-kbd-groupInline wrapper for a combination
.jl-kbd-group__plusThe + separator between caps