DEV Community

Discussion on: Reasons not to use IDs in CSS

Collapse
 
equinusocio profile image
Mattia Astorino • Edited

We should all start styling using type selectors and not class. We should start from the lower layer (type) and then go for attributes and class selection, and if we need it, ending with ID's.

Why using a .p {} class when we can use the lower selecto p {} and let users extend/override our style with attributes or classes?

Collapse
 
olafvolafka profile image
OlafVolafka

I feel it the same.

A little example:

  • we have some buttons on a page
  • we want all the buttons to have a border set (we use type selector)
  • then we want for a group of buttons to have a specific color (now we use class to select them)
  • finally we have two buttons having set e.g. unique fonts (in this case we use id to select those buttons with unique properties)