HTML attributes provide additional information about HTML elements.
They are always written in the opening tag and follow this format:
attribute="value"
Attributes help in:
The id attribute is used to uniquely identify a single HTML element on a webpage.
🔑 Rule:
<tag id="uniqueName">Content</tag>
<h2 id="mainHeading">Welcome Page</h2>
<p>This paragraph belongs to the main section.</p>

<style>
#mainHeading {
color: blue;
}
</style>
<a href="#contact">Go to Contact</a>
<h2 id="contact">Contact Section</h2>
The class attribute is used to group multiple elements under a common name.
📌 One class can be used for:
<tag class="className">Content</tag>
<p class="info">Paragraph one</p>
<p class="info">Paragraph two</p>
<p class="info">Paragraph three</p>

<style>
.info {
color: green;
font-size: 18px;
}
</style>
An element can have more than one class.
<p class="info highlight">Highlighted text</p>
| Feature | ID | Class |
|---|---|---|
| Uniqueness | Unique | Reusable |
| Usage | One element | Multiple elements |
| CSS Selector | #id | .class |
| JS Access | getElementById() | getElementsByClassName() |