Kbd marks keyboard or other user input, so shortcut instructions become easier to recognize.
What You Need to Know
Keep the surrounding sentence readable and use separate kbd elements for distinct keys if that helps explain a combination.
The goal is not to collect as many tags as possible. Pick the element that best describes what the content really is.
Example: See It in Action
Try this markup in a fresh practice file. The next section explains the parts worth paying attention to.
This is a short HTML fragment. To try it as a webpage, put it inside the body element of a complete HTML document.
<p>Press <kbd>Ctrl</kbd> + <kbd>S</kbd> to save.</p>
<p>On macOS, use <kbd>Command</kbd> + <kbd>S</kbd>.</p>
<p>Keyboard keys are marked as user input.</p>
Let’s Understand the Example
- Kbd identifies keys or other input that a person should type.
- A p groups a paragraph of related text. Start another paragraph for a new thought.
Look for the text “Press” in the page. If the visible result surprises you, inspect the rendered elements to see what the browser actually built.
What Should You See?
The page should include “Press”. If it looks different from what you expected, open developer tools and compare the source with the elements the browser created.
Try removing one piece of markup in a scratch copy, refresh the page, and compare the behavior. This is often the fastest way to understand what that piece contributes.
Try It Yourself
- Write the keyboard shortcut for saving on your computer.
- Save your changes, open or refresh the page, and compare the result with the original example.
- Tell a friend what your change did. If you are not sure, undo it, refresh the page, and compare.
Common Beginner Mistakes
- Using kbd to show output produced by the computer rather than input by the user.
- Avoid picking tags just for their default bold, italic or spaced appearance. Use CSS for presentation.
Key Takeaways
- Kbd marks keyboard or other user input, so shortcut instructions become easier to recognize.
- Kbd identifies keys or other input that a person should type.
- Keep the surrounding sentence readable and use separate kbd elements for distinct keys if that helps explain a combination.