Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS CSS Basics (2014) Basic Selectors Reusing Classes

ID vs Classes

Since we are able to use class for more than one element as oppose to ID. Is it okay to use class and not ID? Just to keep things simple.

3 Answers

Kevin Korte
Kevin Korte
28,148 Points

I'll also add that classes and IDs hold different CSS "point values", which on larger projects can lead to some really gnarly specificity problems.

I highly recommend you read this: https://css-tricks.com/specifics-on-css-specificity/

and use IDs responsibly. My personal workflow is that I also default to using a class to style. If I need an ID to style, I need to make a valid point why. For the most part I attach jQuery calls to element IDs.

Good points!

You're welcome! One more thing might be important to point out:

It's not merely the case that there must be only one instance of a specific ID per document, it's ALSO true that each element can have only one ID. Conversely, an element can have multiple classes:

<p class="large-12 columns"> placeholder text </p>

In the above example, the p element has two classes: "large-12" and "columns" (each separated by a space). This cannot be done with IDs.

Yes. The only unique role of an ID is that since there must be only one per document, it's a better way to ensure that only one item is being targeted.

Thank you James! I appreciate the quick response!