0 votes
asked in HTML by (545 points)
HI All

   what is difference between id and class in html

1 Answer

0 votes
answered by (4.2k points)

ID's are unique

  • Each element can have only one ID
  • Each page can have only one element with that ID

Classes are NOT unique

  • You can use the same class on multiple elements.
  • You can use multiple classes on the same element.

Javascript cares

JavaScript people are already probably more in tune with the differences between classes and ID's. JavaScript depends on there being only one page element with any particular, or else the commonly used getElementById function wouldn't be dependable.