Html – Cascading style sheets use “id” or “class”

csshtml

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 ?

Best Solution

ids identify elements. classes classify elements.

Put a class on an element if "it's a kind of ..." (e.g. address)

Put an ID on an element if "it is the ..." (e.g. navigation)