How to Define Keyboard Inputs in HTML

How to Define Keyboard Inputs in HTML

Ferenc Almasi β€’ 2021 April 28 β€’ Read time 1 min read
  • twitter
  • facebook

If you want to define some text as a keyboard input, in a semantically meaningful way in HTML, you can use the less-known kbd tag:

Copied to clipboard!
    New updates available.
    Press <kbd>ctrl</kbd>+<kbd>r</kbd> to reload.

Everything you write inside it will be displayed with the browser's default monospace font. With some help of CSS, you can enrich it to get a look similar on GitHub:

Copied to clipboard! Playground
kbd {
    padding: 3px 5px;
    font-size: 11px;
    line-height: 10px;
    color: #b1bac4;
    background-color: #0d1117;
    border-bottom-color: #6e7681;
    border: 1px solid #6e7681;
    border-radius: 6px;
    box-shadow: inset 0 -1px 0 #6e7681;
    vertical-align: middle;

This will result in the following:

New updates available. Press ctrl+r to reload.

Regarding support, it is well supported in the latest version of major browsers, but not in older versions.

How to Define Keyboard Inputs in Text in HTML
If you would like to see more Webtips, follow @flowforfrank

10 Best Practices for HTML


  • twitter
  • facebook
Did you find this page helpful?
πŸ“š More Webtips
Frontend Course Dashboard
Master the Art of Frontend
  • check Access 100+ interactive lessons
  • check Unlimited access to hundreds of tutorials
  • check Prepare for technical interviews
Become a Pro



This site uses cookies We use cookies to understand visitors and create a better experience for you. By clicking on "Accept", you accept its use. To find out more, please see our privacy policy.