59. Id Attribute
59. Id Attribute
The id attribute specifies a unique id for an HTML element. The value must be
unique within the HTML document.
The id attribute is most 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> www.geekyshows.com </title>
</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>
<html>
<head>
<style>
#geekyshows {
color: red; font-size: 60px;
}
</style>
</head>
<body>
<p id="geekyshows">Hello World!</p>
<p>This paragraph is not affected by the style.</p>
</body>
</html>