Kbd
Shows keyboard keys and shortcuts in text.
Installation
bash
npx bootcn add kbdbash
pnpm dlx bootcn add kbdbash
yarn dlx bootcn add kbdbash
bunx --bun bootcn add kbdThe CLI also installs the design tokens and these components: none. It prints the <link> and <script> tags to add to your layout.
Usage
Wrap each key in <kbd class="bootcn-kbd">, and a combination in .bootcn-kbd-group. Write the key names out where symbols may be unclear ("Ctrl" rather than "^").
Accessibility
<kbd>marks keyboard input; screen readers read the key names as text.- Text keeps 4.5:1 contrast on the muted background.
Dependencies
- Bootstrap 5.3+ CSS.
themes/tokens/tokens.css.
Source
The exact files the CLI installs (kbd@1.0.0). View on GitHub · Report an issue
html
<p>
Press <kbd class="bootcn-kbd">Ctrl</kbd> <kbd class="bootcn-kbd">K</kbd> to search, or
<kbd class="bootcn-kbd">Esc</kbd> to close.
</p>
<p class="mb-0">
Shortcut:
<span class="bootcn-kbd-group">
<kbd class="bootcn-kbd">⌘</kbd>
<kbd class="bootcn-kbd">Shift</kbd>
<kbd class="bootcn-kbd">P</kbd>
</span>
</p>css
.bootcn-kbd {
display: inline-flex;
align-items: center;
justify-content: center;
min-width: 1.25rem;
height: 1.25rem;
padding: 0 0.3125rem;
border: var(--bootcn-border-width) solid var(--bootcn-border-color);
border-radius: var(--bootcn-radius-sm);
background-color: var(--bootcn-muted);
color: var(--bootcn-muted-foreground);
box-shadow: none;
font-family: var(--bs-body-font-family);
font-size: 0.75rem;
font-weight: 500;
line-height: 1;
vertical-align: middle;
}
.bootcn-kbd-group {
display: inline-flex;
align-items: center;
gap: 0.25rem;
vertical-align: middle;
}
