Which attribute is a higher priority in the CSS attribute ID or class?

1 answer 1

id - identifier, can be used to define one element (mainly used if js is applied to an element). The identifier is denoted by the name that follows the pound sign ( # ).


class - can be used to define multiple elements. In CSS, the class selector is denoted by the name that follows the dot ( . ).

By specificity (weight), the presence of id in the selector gives a higher priority than the presence of a class!

Those.

 #my-id {color: red; } .my-class {color: green; } 
 <div class='my-class' id="my-id">Применятся стили id</div> 

ps: if you about it!

  • Thank you, yes about this - TomasRedl Nov.