HTML/CSSBeginner#html#attributes

What is the difference between the id and class attributes?

id must be unique within a page and is used for a single specific element (anchors, JS hooks, label association). class can be applied to multiple elements and is used for reusable styling and grouping.

Example
<div id="main-header" class="header dark-theme">...</div>

Related Questions

1
HTML/CSSAdvanced#html#javascript

What is the <template> element used for?

Open
2
HTML/CSSAdvanced#html#security

What is the difference between the <iframe> sandbox attribute values?

Open
3
HTML/CSSIntermediate#html#performance

How do you lazy-load images natively in HTML?

Open