Log in Sign Up

For CSS, Use Class, not ID

I'm sure many of you heard the same thing from your web design 101 instructor: if you're styling an object that only appears once on a page, use ID. If it appears more than once, use class. Well, here's our version of this 'rule': If you're styling an object, use class. Period.

The reasoning behind this is simple. If you apply a unique style to a div on a page using ID and later want to apply the same style to a second div, what are your options? You must either copy the styles from the first div and paste them to a new, unique ID, or you need to change the ID of the first div to a class. If you would have declared the ID as a class in the first place, you wouldn't have to copy/paste or rewrite any CSS. You'd simply just apply the same class. And if you don't use the class for anything else, who cares? It won't cause any problems if a class is only used once on a page.

Don't get me wrong, IDs are an important part of your web designer's toolkit, but much better suited to JavaScript, forms, named anchors, etc. For CSS, use class.

Try MagicEdit today!

Sign Up for free Demo
Scroll to Top