when styling specific html elements, i tend to always use the class attribute. the css code looks cleaner imo.
why do both exist which one should you use and when ?<
As far a HTML is concerned, an id identifies a single element in the DOM and each element can only have one unique id, whereas a class classifies one or many elements in the DOM and each element can have multiple classes.
...
Also from a CSS perspective, remember that the order of importance goes from least specific to most specific. So, #id
properties override .class
properties, which in turn override tag
properties. Therefore, #id
styles trump .class
styles unless certain class properties are flagged !important
.
This text is red.
This text is blue.