What is HTML <kbd> Tag?
The HTML kbd tag is used to represent user input from a keyboard, voice input, or any text entry device. The content inside the kbd tag is typically rendered in a monospace font and styled to look like keyboard input.
This tag is important for documentation, tutorials, and user interfaces where you want to show keys, shortcuts, or exact input. Search engines and screen readers can understand that the text is user input when you use the kbd tag correctly. It is placed inside the body of an HTML document and can be used anywhere inline text appears.
Syntax of the HTML <kbd> Tag
<kbd>user input</kbd>
The tag contains plain text that represents the user action or keys. For example, use <kbd>Ctrl</kbd> and <kbd>C</kbd> to show a keyboard shortcut.
Examples of HTML <kbd> Tag
Example 1: Basic HTML kbd Tag
<!DOCTYPE html>
<html lang="en">
<head>
<title>Keyboard Input Example - Scholar247</title>
</head>
<body>
<p>To copy text, press <kbd>Ctrl</kbd> + <kbd>C</kbd>.</p>
</body>
</html>
Explanation:
This basic example shows how to display keyboard keys in a sentence. The kbd tag wraps each key so users clearly see which keys to press. The example includes Scholar247 in the title to match site context.
Example 2: Practical / SEO-optimized kbd Tag
<!DOCTYPE html>
<html lang="en">
<head>
<title>How to Save - Scholar247 Shortcut</title>
</head>
<body>
<h1>Save Document</h1>
<p>Press <kbd>Ctrl</kbd> + <kbd>S</kbd> to save your document quickly. </p>
<p>For Mac users, press <kbd> </kbd> + <kbd>S</kbd>.</p>
</body>
</html>
Explanation:
This practical example shows common save shortcuts for Windows and Mac. Using clear text and the kbd tag helps both users and search engines understand the content. Including Scholar247 in the title helps with site-specific relevance and SEO.
Attributes of the HTML <kbd> Tag
The kbd tag does not have special attributes of its own. It is a simple inline element meant to mark up user input. Common HTML global attributes (like id, class, title, style) can be used with kbd to control styling or scripting.
Because the kbd tag primarily conveys semantic meaning (user input), use CSS classes or ARIA attributes when you need additional accessibility or styling control.
Best Practices for HTML <kbd> Tag
• Use kbd for single keys or short key combinations only.
• Combine multiple kbd elements for multi-key shortcuts (for example: <kbd>Ctrl</kbd> + <kbd>Alt</kbd> + <kbd>Delete</kbd>).
• Keep text inside kbd short and exact; avoid long sentences inside the tag.
• Use CSS to ensure kbd displays clearly on all devices (monospace font and subtle background).
• Provide alternate instructions for users on different platforms (Windows, Mac, mobile).
• Use ARIA attributes or descriptive surrounding text for accessibility when needed.
FAQs on HTML <kbd> Tag
What is the HTML kbd tag used for?
The kbd tag marks up user input such as keyboard keys, shortcuts, or typed text and typically renders in a monospace style to visually represent input.
Does the kbd tag improve SEO?
The kbd tag itself is semantic and helps search engines understand that the content is user input, but it has minimal direct SEO impact. Use clear, descriptive surrounding text and page titles for SEO benefit.
Can kbd be styled with CSS?
Yes. Apply CSS classes or styles to kbd to change font, background, padding, and border so the key appearance is consistent and accessible across devices.
Is kbd accessible for screen readers?
Screen readers announce the text inside kbd like normal text. To enhance accessibility, include descriptive context (for example, “press the Enter key”) and use ARIA attributes if necessary.
Should I use kbd for mouse actions or touch gestures?
No. kbd is intended for textual user input and keyboard keys. For mouse actions use descriptive text or use elements like <mark> or aria-labels. For touch gestures, describe the gesture in plain text.