The id attribute specifies a unique id for an HTML element. The value must be unique within the HTML document.
The id attribute is mostly used to point to a style in a style sheet, and by JavaScript (via the HTML DOM) to manipulate the element with the specific id. The id attribute can be used on any HTML element.
Rules
- Must begin with a letter A-Z or a-z.
- A class name cannot start with a number.
- Must not contain any space characters.
- Can be followed by: letters (A-Za-z), digits (0-9), hyphens (“-“), and underscores (“_”).
- In HTML, all values are case-insensitive.
<html>
<head>
<title> id attribute</title>
<style>
#top{
color: blue;
}
#imp{
color: brown;
}
</style>
</head>
<body>
<a href="#imp">Important</a>
<p id="top">
Once upon a time, all the birds - the swans, cranes, </p>
<h3 id="imp">
Goodwill is that unseen force which is </h3>
<p>He has neither the time, nor the interest to bother </p>
<a href="#top">Go to Top</a>
</body>
</html>