Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
Why we use ID
I know IDs have more weight then classes. But I wanted to know in which specific scenarios we need to use IDs?
Josh Sneddon15,943 Points
Thomas Workman7,173 Points
Classes are used for global attributes, however, I recommend to all that you avoid using ID's, unless it is absolutely necessary. You can still achieve the same desired styling using a class without running into specificity issues later with ID's. You don't want to be putting ID's on everything to get your styles to come to life. Using classes will make your code much easier to work with, especially as your app grows. My two cents anyway, take it for what it's worth or don't.
Maxwell DeMers6,853 Points
In my experience, IDs are used when you want to specify something for styling purposes, if only one element should be styled that way. You can have several elements with the same class, but may want just one of them to be a little different. That is when I use IDs.
Let me know if you'd like more specifics.
Alex Flores7,864 Points
This is the way I understand it and so far, it's been working well for me. Classes are, so to speak, css global attributes. That is, they can be used in any element and are very versatile. IDs are not. IDs are best used for manipulating specific elements via JS or CSS.