The HTML tabindex attribute defines the tab order of an element (when the “tab” button is used for navigating).
The HTML tabindex attribute can be used on all HTML elements.
Syntax:
<element tabindex="number">
number – defines the tabbing order of the element.
Example:
<!DOCTYPE html>
<html>
<body>
<p tabindex="1">This is some text.</p>
<p tabindex="3">This is another text.</p>
<p tabindex="2">...and another text.</p>
</body>
</html>
Output:
Try navigating the elements by using the “Tab” button on your keyboard:
It is a good practice to include the HTML lang attribute inside the <html> tag, to declare the language of your website (this is meant to assist search engines and browsers):
The HTML id attribute is used to define a special id for an HTML element.
The value of the HTML id attribute needs to be unique within the HTML document (you cannot have more than one element with the same id in an HTML document).
Syntax:
<element id="idname">
idname – defines a unique id for the element (should contain at least one character, shouldn’t contain any space characters).
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="example-style.css">
</head>
<body>
<h4>This is a heading.</h4>
<p>This is a paragraph.</p>
<p>This is the second paragraph.</p>
</body>
</html>
_blank – opens the linked document in a new window or tab.
framename – opens the linked document in the named iframe.
_parent – opens the linked document in the parent frame.
_self (default) – opens the linked document in the same frame as it was clicked.
_top – opens the linked document in the full body of the window.
Example:
<!DOCTYPE html>
<html>
<body>
<p>Open link in a new tab: <a href="https://www.lenastanley.com/" target="_blank">CodeLife:Animations</a></p>
</body>
</html>
The HTML style attribute defines a style for an element (can be used on all HTML elements).
The HTML style attribute overrides any style set globally (for example styles defined in the <style> tag).
Example:
<!DOCTYPE html>
<html>
<body>
<p style="color:#e76f51; text-decoration: underline;">This is a paragraph.</p>
<h4 style="color:#264653; background-color: #e9c46a;">This is a header.</h4>
</body>
</html>