HTML ID Attribute: Definition, How to use, Syntax
Definition: The HTML ID attribute defines a unique value for a single element. The class attribute can be used to make changes in the style sheet and JavaScript. in CSS, we donate ID with a hash (#).
Syntax:
id=”id name”
Example:
<!DOCTYPE html>
<html>
<head>
<style>
#test {
background-color: blue;
color: white;
border: 2px solid red;
margin: 30px;
padding: 10px;
}
</style>
</head>
<body>
<h2 id="test"> HTML </h2>
<p> Hyper Text Markup Language </p>
</body>
</html>
You can specify different ID for different sections or paragraphs. for Example:
<!DOCTYPE html>
<html>
<head>
<style>
#test1 {
background-color: blue;
color: white;
border: 2px solid red;
margin: 30px;
padding: 10px;
}
#test2 {
background-color: black;
color: white;
border: 2px solid red;
margin: 30px;
padding: 10px;
}
#test3 {
background-color: purple;
color: white;
border: 2px solid red;
margin: 30px;
padding: 10px;
}
</style>
</head>
<body>
<div id="test1">
<h2> HTML </h2>
<p> Hyper Text Markup Language </p>
</div>
<div id="test2">
<h2> Use of HTML </h2>
<p> HTML is used for creating Web pages. </p>
</div>
<div id="test3">
<h2>Learn HTML With @ PrepareExams </h2>
<p>HTML Tutorials are here to learn</p>
</div>
</body>
</html>