The HTML <kbd> tag
Definition and Usage
<kbd>
The tag is used to define keyboard input. The content is displayed in the browser's default monospace font.
Tip:This tag is not deprecated. However, richer effects can be achieved by using CSS (see the example below).
See also:
Tag | Description |
---|---|
<code> | Define the sample output of a computer program. |
<samp> | Define keyboard input. |
<var> | Define variables. |
<pre> | Define preformatted text. |
See also:
HTML Tutorial:HTML Text Formatting
HTML DOM Reference Manual:Kbd Object
Instance
Example 1
Define some text in the document as keyboard input:
<p>Press <kbd>Ctrl</kbd> + <kbd>C</kbd> to copy the text (Windows).</p> <p>Press <kbd>Cmd</kbd> + <kbd>C</kbd> to copy the text (Mac OS).</p>
Example 2
Use CSS to set the style of the <kbd> element:
<html> <head> <style> kbd { border-radius: 2px; padding: 2px; border: 1px solid black; } </style> </head> <body> <p>Press <kbd>Ctrl</kbd> + <kbd>C</kbd> to copy the text (Windows).</p> <p>Press <kbd>Cmd</kbd> + <kbd>C</kbd> to copy the text (Mac OS).</p> </body> </html>
Global Attributes
<kbd>
The tag also supports Global Attributes in HTML.
event attributes
<kbd>
The tag also supports Event Attributes in HTML.
Default CSS Settings
Most browsers will display the following default values <kbd>
Element:
kbd { font-family: monospace; }
Browser Support
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Support | Support | Support | Support | Support |