The Difference Between ID and Class in CSS

The difference between an ID and a class is that an ID can be used to identify one element, whereas a class can be used to identify more than one.

The benefit of this is that you can have the same HTML element, but presented it differently depends upon its class and id properties. 

HTML elements can have both class and Id  selectors.

<div class = "box"  id = "header">
    .............
    .............
</div>

In the CSS, a class selector is a name preceded by a full stop (“.”) and an ID selector is a name preceded by a hash character (“#”).

  





ID's are unique


  • Each Element can has only one id.
  • Each page can have only one element with that ID.


CLASSES are Not unique


  • we can use same class on multiple elements
  • we can use multiple class on the same elements












Comments

  1. Is there any problem to have same id to multiple html tags.

    ReplyDelete

Post a Comment

Popular posts from this blog

Hyperparameter tuning for machine learning models.

What is difference between Yield and return Keyword in Python