The id Attribute
The id attribute assigns a unique identifier to an element. These identifiers are used to apply styles to an element or to select an element with JavaScript.
To apply a style based on an id attribute value, you prefix id with the # character.
<!DOCTYPE HTML>
<html>
<head>
<title>Example</title>
</head>
<style>
#w3clink {
background: grey;
color: white;
padding: 5px;
border: thin solid black;
}
</style>
<body>
<a href="http://java2s.com">java2s.com web site</a>
<p />
<a id="w3clink" href="http://w3c.org">W3C web site</a>
</body>
</html>
The id attribute allow to navigate to a particular section in a document.
For example, example.html#myelement can nevigate to an element whose id is myelement in example.html. The # plus the element id is known as the URL fragment identifier.
Home
HTML CSS Book
HTML
HTML CSS Book
HTML
HTML5 Global Attributes:
- The accesskey Attribute
- The class Attribute
- The contenteditable Attribute
- The contextmenu Attribute
- The dir Attribute
- The draggable Attribute
- The dropzone Attribute
- The hidden Attribute
- The id Attribute
- The lang Attribute
- The spellcheck Attribute
- The style Attribute
- The tabindex Attribute
- The title Attribute
Related: