About Lesson
Definition:
The id attribute is used to define a unique identifier for an HTML element. It is commonly used to point to a style in a style sheet, as well as anchor links and targets for scripts. The id value is case-sensitive and should be unique within the HTML document.
This attribute can be used by CSS and JavaScript (via the HTML DOM) to perform specific tasks for the element with the specified id.
In CSS, you must write a hash ( # ) character followed by the id of the element for selecting the element with a specified id. It must have at least one character, and must not contain whitespace (tabs, spaces, etc.).
In HTML5, the id attribute can be used for any HTML element.
Example:
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>HTML Id</title>
<style>
#demo1 {
color: white;
text-align: center;
background-color: blueviolet;
}
#demo2 {
color: brown;
font-size: 30px;
}
#demo3 {
color: purple;
font-size: 30px;
}
</style>
</head>
<body>
<h1 id="demo1">HTML CLASSES</h1>
<h3 id="demo2">hello!</h3>
<p id="demo3">This is Id Attribute</p>
</body>
</html>