The basics: the difference between a CSS id and class

Cascading Style Sheets

Cascading Style Sheets

You find this answer everywhere on Google, why people just don’t look it up I don’t know (rant over).

Anyway, I get this question all the time: What’s the difference between “id” and “class” (If I had a pound for each time that question…)?

  • id – a unique identifier, only
  • class – this is a selector that can apply to many elements at once, or a sub-set of specific HTML elements.

In short add this to any element to which you want to give that extra garnish, but don’t add just the sake of it, always justify what you are doing; avoid code bloat.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.