HTMLEasy
What is the difference between the id and class attributes?
By FrontendPro Editorial Team Updated 8/14/2026
#html#css
Answer
idmust be unique in a document; it powers anchors (#section),label[for],aria-labelledby,getElementById.classis reusable and is the primary hook for styling.
html
<label for="email">Email</label>
<input id="email" class="field field--lg" />
On specificity: id (1,0,0) outranks class (0,1,0), so avoid styling by id - it becomes hard to override.
