Live Preview
Common shortcuts in a documentation sentence:
Save your work with Ctrl + S or open the command palette with Ctrl + Shift + P.

By the end of this tutorial, you’ll mark up keyboard keys and shortcuts clearly in tutorials, docs, and help content.
Wrap keys and key names in <kbd> opening and closing tags.
Represent keys like Enter, Esc, and Tab in prose.
Show shortcuts such as Ctrl+C with one kbd per key.
Distinguish keyboard input from source code and program output.
Style keys like physical buttons with borders, shadows, and fonts.
Write shortcuts that screen readers and all users can follow.
<kbd> Tag?The keyboard input element (<kbd>) represents text the user enters via a keyboard — including individual keys, key names, and combinations used as shortcuts. Browsers typically render it in a monospace font with a subtle button-like appearance.
Use <kbd> when you mean keys the user presses. Do not use it for source code (<code>) or program output (<samp>).
The element is inline, so it fits naturally inside paragraphs, list items, and table cells. It is ideal for software tutorials, keyboard shortcut references, and accessibility documentation.
Wrap the key name or combination between opening and closing <kbd> tags:
<kbd>Enter</kbd><kbd> is an inline phrasing element — it nests inside paragraphs and lists.<kbd> tag.+ or the word then between keys as plain text.style attributes in production HTML.| Use Case | Code Snippet | Result |
|---|---|---|
| Single key | <kbd>Enter</kbd> | Enter |
| Two-key shortcut | <kbd>Ctrl</kbd> + <kbd>C</kbd> | Ctrl + C |
| Styled key | <kbd class="key"> | Esc |
| Source code | <code>console.log()</code> | console.log() Use code, not kbd |
| Program output | <samp>Hello</samp> | Use samp, not kbd |
| Mac shortcut | <kbd>Cmd</kbd> + <kbd>S</kbd> | Cmd + S |
<kbd>, <code>, and <samp>These inline elements look similar but communicate different meaning:
| Element | Represents | Example |
|---|---|---|
<kbd> | Keyboard input the user types | Ctrl + V |
<code> | Source code or programmatic text | git commit -m |
<samp> | Sample output from a program | File saved successfully. |
| Together | Press kbd, run code, see samp | Tutorial flow |
The <kbd> element has no unique attributes. Use global attributes for styling and extra context:
class GlobalCSS hook for consistent key styling across your documentation site.
class="key key--primary"title GlobalOptional tooltip with extra detail, such as the full shortcut name.
title="Copy to clipboard"id GlobalUnique identifier when linking to a specific shortcut definition.
id="shortcut-copy"lang GlobalLanguage of the key label when documenting localized keyboard layouts.
lang="en"<kbd
class="key"
title="Copy to clipboard"
>Ctrl</kbd> + <kbd class="key">C</kbd>Prefer CSS classes over inline styles for reusable keyboard key design.
Styled keys, single-key instructions, and multi-key shortcuts with copy-ready code and live previews.
Common shortcuts in a documentation sentence:
Save your work with Ctrl + S or open the command palette with Ctrl + Shift + P.
Combine class with CSS to make keys look like physical buttons.
<p>Press the key: <kbd class="key">Space</kbd></p>Use <kbd> in software tutorials, keyboard shortcut cheat sheets, accessibility guides, and inline help text wherever users need to know which keys to press.
Mark one key when instructing users to press Enter, Tab, or Escape.
<p>Press the <kbd>Enter</kbd> key to submit the form.</p>Wrap each key separately so screen readers and parsers understand the full shortcut.
<p>To copy text, press <kbd>Ctrl</kbd> + <kbd>C</kbd>.</p>Browsers give kbd a default monospace look. Customize it to match your docs design system:
border Button-like key capbox-shadow Raised key effectfont-family Monospace key labelsgap Space between combo keys/* Keyboard key styling */
kbd {
font-family: ui-monospace, monospace;
font-size: 0.875em;
padding: 0.15rem 0.45rem;
border: 1px solid #cbd5e1;
border-radius: 4px;
background: #f8fafc;
box-shadow: 0 1px 0 #e2e8f0;
color: #0f172a;
}
kbd.key--accent {
background: #eff6ff;
border-color: #93c5fd;
color: #1e40af;
}
.shortcut {
display: inline-flex;
align-items: center;
gap: 0.35rem;
}Live styled shortcut
Undo with Ctrl + Z
Clear keyboard markup helps every user follow your instructions:
Enter, not a symbol alone, when meaning matters.Wrap key names in kbd inside tutorials or help text.
User-agent styles render keys in monospace with a subtle inset or border.
Custom classes make shortcuts look like physical keys in your design system.
Readers instantly recognize which keys to press in your documentation.
The <kbd> element is fully supported in all browsers, including legacy Internet Explorer.
From legacy Internet Explorer to the latest mobile browsers — the kbd element is fully supported for documenting shortcuts.
Bottom line: Ship keyboard shortcut docs with confidence. The <kbd> element is safe to use in every production environment today.
Mastering the <kbd> tag helps you document keyboard input accurately in HTML. Whether writing software tutorials, help articles, or accessibility guides, semantic key markup makes instructions clearer and more professional.
Remember to use one kbd per key, distinguish kbd from code, and style keys with CSS classes for a consistent look across your site.
kbd for keys the user physically presses<kbd> for combinationscode when showing commands to runkbd for source code snippetskbd tagkbd with samp program output<kbd>Bookmark these before you ship — they’ll keep your shortcut docs semantic and readable.
<kbd> marks keys the user types or presses.
Split Ctrl + C into separate elements.
SyntaxUse code for source code, not keyboard keys.
Borders and shadows make shortcuts easy to scan.
DesignDocument Cmd vs Ctrl for Mac and Windows users.
AccessibilityWorks in every browser, including legacy IE.
CompatibilityEnter or Ctrl+C in tutorials.kbd is for keys the user presses. code is for source code, commands, or programmatic text.<kbd> and place + between them: <kbd>Ctrl</kbd> + <kbd>C</kbd>.class for styling and title for optional tooltips.kbd element has universal support in all modern and legacy browsers.Try styled keys, single-key instructions, and Ctrl+C combinations in the interactive editor.
6 people found this page helpful