I've always used the class
attribute, never id
for the purpose of CSS selecting and styling. I know that the id
must be unique, but that doesn't seem to be a reason to use it for CSS.
The only reason I have used the id
attribute is for JavaScript and form labelling.
I find mixing id
and class
for the purpose of CSS can cause confusion, and for me it's a good way to force separation of style and behaviour.
Is there a good reason to use id
for CSS purposes? Is there anything that can be achieved with id
that can't be done with class
?
Comments I found useful/interesting
Using ID for styling makes sense if it's an element that doesn't have duplicate, especially if it's something that shows up in all/most pages.
E.g.:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With