re: Reasons not to use IDs in CSS VIEW POST


What is the your recommendation for use of id's? I'm currently using them for single page elements that are not going to be reused i.e. a front page carousel or a contact form that won't be reused. Is there any reason you can't just use classes all the time?


No there's no reason you can't use classes everywhere for styling. Even if you think you'll only want to use a style once, there's no reason not to use a class for it. I can see why you would define "single-use" styles on the IDs but there isn't any advantage to doing that except for the higher specificity. I prefer to reserve IDs for other uses such as form labels and linking to anchor tags and keep all my styles defined by classes, for consistency.

Code of Conduct Report abuse