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 trialAdam Lyon
1,061 PointsWhy use ID instead of Class?
Looking at the parameters for both these selectors, I can't see the benefit of using ID when Class can be used to apply the same changes to every instance in the document. Is there a marked reason to use ID instead?
5 Answers
Steven Parker
231,059 PointsID is a better choice when there is only one item to be targeted, since every element ID on the document must be unique.
Fran ADP
6,304 PointsIt is a better choice.
Muhammad Khan
Courses Plus Student 8,772 PointsHi there, ID is a better choice when unique element to be targeted.
Kirt Perez
7,374 PointsWhat's wrong with using only one element that has a class that is only used once? Why not just stick to just class selectors?
Steven Parker
231,059 PointsTechnically, a class will do the job just fine; but using an ID makes it clear at first glance at the CSS that the rule targets one unique element.
Muhammad Khan
Courses Plus Student 8,772 PointsHi there, an id can be used to identify one element, whereas class can be used to identify more than one. id is unique. So, id is a better choice when unique element to be targeted.