HTML id Attribute

An HTML identifier is used to specify a unique HTML object id.

You cannot have more than one item with the same ID in an HTML document.

Using The id Attribute

id identifier specifies a unique HTML object id. The id identifier value must differ within an HTML document.

The id identifier is used to identify a specific style declaration on a style sheet. It is also used by JavaScript to access and manage an object with a specific id.

Id syntax says: type hash character (#), followed by id name. Then, define CSS features within folded parentheses {}.

In the following example we have the <h1> object pointing to the id name "myHeader". This <h1> section will be styled according to the #myHeader style description in the header section:

Example
<!DOCTYPE html>
<html>
<head>
<style>
#myHeader {
  background-color: lightblue;
  color: black;
  padding: 40px;
  text-align: center;
}
</style>
</head>
<body>

<h1 id="myHeader">My Header</h1>

</body>
</html>