In HTML language, an ID identifies a specific element within a page and must be unique, whereas
CLASS marks an element as members of a group and can be used multiple times.
The question is why not always using Class over ID ? One of the main reason may be related to javascript that intensively uses ID such as in the function getElementById(). Another reason is that an element may have both a class and an ID.
<div class="tab" id="tab1" > Tab 1 </div>
<div class="tab" id="tab2" > Tab 2 </div>
Then in your CSS you access to the class or id as follows:
div.tab { background-color: #F00; }
div#tab1 { text-decoration: none; }
Please follow and like us: