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 ID Selectors

How do you think about using class selectors over ID selectors?

I stumbled upon this article http://oli.jp/2011/ids/ and found it very convincing in its claim to not use ID selectors anymore.

How do you guys think about it and especially how does the treehouse team think about it, because this is an updated course and you still teach the ID selector beside its use as fragment identifier.

3 Answers

Jenny Veens
Jenny Veens
10,896 Points

Hi Katsumi,

I try to use classes whenever possible, but I DO still use IDs in one-page websites so that I can target specific sections with menu links, and then implement a smooth scroll effect as that page moves to the specified area of the site.

So you use it for fragment identifiers/anchors and not for styling purposes, makes sense and is what the article suggests :)

Jason Hess
Jason Hess
4,789 Points

All great points above, Keep in Mind. You cannot have multiple id's with the same name. Classes can be reused as many times as you like, especially if those specific styles you are applying correspond to that specific class name. I'm sure Guil will get to this later in the course. I personally use both ID's and classes depending on the site and situation.

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

I still use id's if I know I won't need to us it for styling of anything else. For example if I use a contining wrapper div, by default I give this an ID. But for most other things I give it a class. :-)

But wouldn't you agree that you could do this with a class as well? I guess it's more of a personal choice than a functional necessity, right?

I'm just trying to find out, if there is something I'm missing here since this article is the first opinion I've found, claiming that IDs are obsolete and still I find them in professional, up to date training courses, websites and blog themes.