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 ?<
You go with in this order of preference:
ID is by far the fastest lookup. Next fastest is lookup by tagname. Slowest is by class name.
As for when to use classes or IDs, you use IDs when you can and classes when you can't.