From 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 7 Apr 2024 13:41:34 -0500 Subject: new repository --- devdocs/html/element%2Fkbd.html | 155 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100644 devdocs/html/element%2Fkbd.html (limited to 'devdocs/html/element%2Fkbd.html') diff --git a/devdocs/html/element%2Fkbd.html b/devdocs/html/element%2Fkbd.html new file mode 100644 index 00000000..673d315f --- /dev/null +++ b/devdocs/html/element%2Fkbd.html @@ -0,0 +1,155 @@ +

<kbd>: The Keyboard Input element

The <kbd> HTML element represents a span of inline text denoting textual user input from a keyboard, voice input, or any other text entry device. By convention, the user agent defaults to rendering the contents of a <kbd> element using its default monospace font, although this is not mandated by the HTML standard.

+

Try it

+
+

<kbd> may be nested in various combinations with the <samp> (Sample Output) element to represent various forms of input or output based on visual cues.

+
+

Attributes

+

This element only includes the global attributes.

+

Usage notes

+
+

Other elements can be used in tandem with <kbd> to represent more specific scenarios:

Note: You can define a custom style to override the browser's default font selection for the <kbd> element, although the user's preferences may potentially override your CSS.

+
+

Examples

+ +

Basic example

+
+
+

html

+
<p>
+  Use the command <kbd>help mycommand</kbd> to view documentation for the
+  command "mycommand".
+</p>
+
+

Result

+
+ + +
+
+

Representing keystrokes within an input

+
+

To describe an input comprised of multiple keystrokes, you can nest multiple <kbd> elements, with an outer <kbd> element representing the overall input and each individual keystroke or component of the input enclosed within its own <kbd>.

Unstyled

First, let's look at what this looks like as just plain HTML.

HTML
+

html

+
<p>
+  You can also create a new document using the
+  <kbd><kbd>Ctrl</kbd>+<kbd>N</kbd></kbd> keyboard shortcut.
+</p>
+
+

This wraps the entire key sequence in an outer <kbd> element, then each individual key within its own, in order to denote the components of the sequence.

Note: You don't need to do all this wrapping; you can choose to simplify it by leaving out the external <kbd> element. In other words, simplifying this to just <kbd>Ctrl</kbd>+<kbd>N</kbd> would be perfectly valid.

Note: Depending on your style sheet, though, you may find it useful to do this kind of nesting.

Result

The output looks like this without a style sheet applied:

+
+ + +

With custom styles

We can make more sense of this by adding some CSS:

CSS

We add a new selector for nested <kbd> elements, kbd>kbd, which we can apply when rendering keyboard keys:

+

css

+
kbd > kbd {
+  border-radius: 3px;
+  padding: 1px 2px 0;
+  border: 1px solid black;
+}
+
+
HTML

Then we update the HTML to use this class on the keys in the output to be presented:

+

html

+
<p>
+  You can also create a new document by pressing the
+  <kbd><kbd>Ctrl</kbd>+<kbd>N</kbd></kbd> shortcut.
+</p>
+
+
Result

The result is just what we want!

+
+ + +
+
+

Echoed input

+
+

Nesting a <kbd> element inside a <samp> element represents input that has been echoed back to the user by the system.

+

html

+
<p>
+  If a syntax error occurs, the tool will output the initial command you typed
+  for your review:
+</p>
+<blockquote>
+  <samp><kbd>custom-git ad my-new-file.cpp</kbd></samp>
+</blockquote>
+
+

Result

+
+ + +
+
+

Representing onscreen input options

+
+

Nesting a <samp> element inside a <kbd> element represents input which is based on text presented by the system, such as the names of menus and menu items, or the names of buttons displayed on the screen.

For example, you can explain how to choose the "New Document" option in the "File" menu using HTML that looks like this:

+

html

+
<p>
+  To create a new file, choose the <kbd><kbd><samp>File</samp></kbd>
+  ⇒<kbd><samp>New Document</samp></kbd></kbd> menu option.
+</p>
+
+<p>
+  Don't forget to click the <kbd><samp>OK</samp></kbd> button to confirm once
+  you've entered the name of the new file.
+</p>
+
+

This does some interesting nesting. For the menu option description, the entire input is enclosed in a <kbd> element. Then, inside that, both the menu and menu item names are contained within both <kbd> and <samp>, indicating an input which is selected from a screen widget.

Result

+
+ + +
+
+

Technical summary

+
Content categories Flow content, phrasing content, palpable content.
Permitted content +Phrasing content.
Tag omission None, both the starting and ending tag are mandatory.
Permitted parents Any element that accepts phrasing content.
Implicit ARIA role No corresponding role
Permitted ARIA roles Any
DOM interface HTMLElement
+

Specifications

+
+ + +
Specification
HTML Standard
# the-kbd-element
+

Browser compatibility

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariWebView AndroidChrome AndroidFirefox for AndroidOpera AndroidSafari on IOSSamsung Internet
kbd112
1Before Firefox 4, creating a <kbd> element incorrectly resulted in an HTMLSpanElement object, instead of the expected HTMLElement.
Yes15≤44.418414≤3.21.0
+

See also

+
+

+ © 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
+ https://developer.mozilla.org/en-US/docs/Web/HTML/Element/kbd +

+
-- cgit v1.2.3