Both class and id are universal HTML attributes that can be used in any HTML element.

A style class can be called multiple times in the same page to style HTML elements. Indeed, calling the same style classe multiple times to apply the same styles is very useful.

In contrast, each ID value should be used only once per page.
For example, if you put id="myId" in an HTML element , then the value myId should not be used again in the same page.
The purpose of the ID attribute is to give an HTML element a unique IDentifier.

Giving an HTML element a Unique ID has several purposes in addition to applying styles. IDs are used to create unique page anchors for "a back to the top link," for example. IDs are also used in JavaScript to uniquely identify an HTML element to apply an interactive effect.

This block is styled with class="myClass".


This block is styled with class="myClass".


This block is styled with id="myId".
The styles in the myId selector should only be used once per page.