What is the difference between class and id in HTML?

Solution

class and id both are used as identifier/selector for any html element. 

For example:- 

<div id="myDiv" class="firstDiv"></div>

The basic difference between class and id is - 

  • id is unique whereas a same class can be applied to multiple elements on the html page. 
  • each element can have only one id whereas each element can have more than one class.

 

Share this thread

Comments

Comments
comments powered by Disqus

Navigation

Social Media