5 Pure CSS2 with JSPublished 2026-10-05Free · no sign-up
Seven ways to show keyboard keys: shortcuts inside a sentence, chunky 3D keycaps, Mac modifier symbols with readable names, a shortcut reference list, keys that light up when you press them, an arrow key cluster and a search field that shows its command palette shortcut.
Keyboard shortcuts written inside a sentence with kbd elements, nested so that each key in a combination is its own kbd inside an outer kbd. The keys are small, with a bottom border for a hint of depth that does not disturb the line height.
View code
<p class="kbd1">Press <kbd><kbd>Ctrl</kbd> + <kbd>K</kbd></kbd> to search, or <kbd>?</kbd> to see all shortcuts.</p>
A chunky keycap with a raised face, made from a gradient face and a deep bottom border. Clicking it presses it down by shrinking the bottom border and moving it, a satisfying detail for keyboard-themed brands.
macOS shortcuts use symbols (⌘ ⇧ ⌥ ⌃) that many people cannot name, so each symbol sits in an abbr with a title and a visually hidden word, giving screen readers Command, Shift, P rather than unreadable glyphs.
View code
<p class="kbd3">Open the command palette: <kbd><kbd><abbr title="Command">⌘</abbr><span class="sr">Command</span></kbd><kbd><abbr title="Shift">⇧</abbr><span class="sr">Shift</span></kbd><kbd>P</kbd></kbd></p>
A keyboard shortcuts panel as a description list: the action on the left as the term, the keys on the right as the description. A dl pairs each shortcut with its action for screen readers, and the layout is a two-column grid.
Press W, A, S or D (or the arrow keys) while the area has focus and the matching keycap lights up, the kind of hint used in games and keyboard tutorials. The area is a focusable group with instructions, and keys are matched with event.code so layouts do not matter.
View code
<div class="kbd5" tabindex="0" role="group" aria-label="Key tester. Press W, A, S or D."><p>Focus here, then press W A S D</p><div class="pad"><kbd data-c="KeyW">W</kbd><kbd data-c="KeyA">A</kbd><kbd data-c="KeyS">S</kbd><kbd data-c="KeyD">D</kbd></div></div>
var box = document.querySelector('.kbd5'), map = { ArrowUp: 'KeyW', ArrowLeft: 'KeyA', ArrowDown: 'KeyS', ArrowRight: 'KeyD' };
function key(e, on) { var c = map[e.code] || e.code, k = box.querySelector('[data-c=' + c + ']'); if (k) { k.classList.toggle('on', on); if (map[e.code]) e.preventDefault(); } }
box.addEventListener('keydown', function (e) { key(e, true); }); box.addEventListener('keyup', function (e) { key(e, false); });
06. Arrow Key Cluster
kbdArrows
The inverted-T arrow cluster used in game instructions and accessibility help pages, with each arrow's name in a visually hidden span so a screen reader says Up arrow rather than reading a symbol.
View code
<p class="kbd6"><span class="lbl">Move with</span><span class="cl"><kbd class="u">↑<span class="sr"> Up arrow</span></kbd><kbd class="l">←<span class="sr"> Left arrow</span></kbd><kbd class="d">↓<span class="sr"> Down arrow</span></kbd><kbd class="r">→<span class="sr"> Right arrow</span></kbd></span></p>
A fake search field that shows the shortcut that opens the real command palette, with Ctrl K on Windows and Linux and ⌘K on Mac, chosen by a one-line platform check. The hint is decorative inside a button whose name says what it does.
if (/Mac|iPhone|iPad/.test(navigator.platform || navigator.userAgent)) document.querySelector('.kbd7 kbd').textContent = '⌘K';
About these CSS Kbd Keys
kbd for keys
The <kbd> element marks keyboard input. For a combination, nest one kbd per key inside an outer kbd, so Ctrl + K is three elements that are styled and read correctly.
Name the symbols
Mac symbols such as ⌘ and ⇧ are unreadable to many people and to screen readers. Add the word, as a title on an abbr and in visually hidden text.
Match the platform
Show Ctrl on Windows and Linux and ⌘ on Mac. A one-line platform check can switch the label; when unsure, show both.
Lists of shortcuts are definitions
A shortcuts panel pairs an action with keys, which is what a description list (<dl>) is for.
Frequently asked questions
Is there a Tailwind version?
Yes, see the Tailwind kbd keys collection.
Why does the key tester use event.code?
event.code refers to the physical key position, so W A S D work on any keyboard layout.
Should I add custom keyboard shortcuts?
Only with a way to see and turn them off, and never on single printable keys inside text fields.