0
Difference between id and class in HTML
pranav m
walmarteasy
0completed
19
Answer
- id
- Unique identifier for a single element.
- Only one per page (shouldn’t repeat).
- Used for:
- Anchors (
#section1) - JS DOM access (
document.getElementById). - CSS:
#idName { ... }
- Anchors (
- class
- Can be used by multiple elements.
- Groups elements with shared styling/behavior.
- An element can have multiple classes.
- CSS:
.className { ... } - JS:
document.getElementsByClassName.
Example
<div id="header">Unique header</div>
<p class="highlight">Paragraph 1</p>
<p class="highlight">Paragraph 2</p>Click to Reveal Answer
Tap anywhere to see the solution
Revealed
Comments0