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 trialRishi Reddy
3,894 PointsCSS vs. ID
What's the benefit of using ID's vs. Classes for styling other than the benefit of linking?
5 Answers
Adam Sackfield
Courses Plus Student 19,663 PointsID's should be unique and used once, whereas classes should be used across multiple elements. See below
#social { // Some styles }
.btn { // Some styles }
As you see the ID social would probably only be used once per page, and the class BTN can be applied to any button.
Also ID takes precedence over classes link
eirikvaa
18,015 PointsChris Coyier has a good article about this.
Rishi Reddy
3,894 Pointsbut can't you just create a class and use it once. what's the benefit of id then.
banned banned
Courses Plus Student 11,243 PointsYou can use classes over and over again, for instance a button let's say you want 3 buttons on your website with the same markup just use the same class.
An ID is can be considered unique on the page.
banned banned
Courses Plus Student 11,243 PointsYou can use classes over and over again, for instance a button let's say you want 3 buttons on your website with the same markup just use the same class.
An ID is can be considered unique on the page.