HTML Reference ยท Inline Text
The <kbd> element
Reference for the HTML <kbd> element: marking keys, shortcuts and other user input, nesting it for key combinations, styling and technical details.
The <kbd> element marks user input: a key to press, a keyboard shortcut, a command to type, or even a voice command or menu choice. Browsers display it in a monospace font.
HTML
<p>Press <kbd>Esc</kbd> to close the dialog.</p>
Try it
An outer <kbd> wraps the whole input; inner <kbd> elements mark each key. The CSS styles only the inner ones as keycaps.
Attributes
This element has no attributes of its own. It accepts the global attributes.
Usage notes
- Nesting.
<kbd>inside<kbd>means individual keys within one input, as in a shortcut.<kbd>inside<samp>means input that the system echoed back on screen.<samp>inside<kbd>means input based on something the system showed, such as a menu item. - Input vs output vs code. Use
<kbd>for what the user types,<samp>for what the program prints, and<code>for code in general. - Name keys clearly. Write key names as they appear on keyboards (
Ctrl,Shift,Enter) and mention platform differences when they exist. - Accessibility. Screen readers usually read the key names as plain text, so symbols like โ or โง may be read oddly. Spelling out "Command" or "Shift", or adding
aria-label, can help.
Technical summary
| Content categories | Flow content, phrasing content, palpable content |
| Permitted content | Phrasing content |
| Tag omission | None; both the start and end tags are required |
| Permitted parents | Any element that accepts phrasing content |
| Implicit ARIA role | No corresponding role |
| DOM interface | HTMLElement |
| Default display | inline (monospace font) |
Browser support
Supported in every browser.
Related
<code>โ computer code<samp>โ sample program output<var>โ a variable- Lessons: Code, Keyboard Input and Program Output, Keyboard Access and Focus