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

HTML How to Make a Website Adding Pages to a Website Add Iconography

Ryan Schmelter
Ryan Schmelter
9,710 Points

Why not use ID instead of class for phone, email, and twitter?

Can anyone explain why ID isn't used in this case? These classes are being used anywhere else on the site.

2 Answers

Christopher Debove
PLUS
Christopher Debove
Courses Plus Student 18,373 Points

Those could be ID. Actually, it should be the case, the classes are too specific for those elements. But I think it's done for didactic purposes.

Evgeniia Mas
Evgeniia Mas
4,452 Points

Hello! I think it is really a developer choice depending on project's features and selectors differencies. If you are going to give the same styles to different elements (same font-size, font-family and so on), you should give them the same class and therefore avoid CSS duplication. If you need to have a specific styles or going to do something with any element, you'd better choose id. As a unique selector (which can be used with that name only once on the one page) it gives you excelent oppotunity to select only that element and for example change it color or use any javascript function - change phone if user selected another city and like that. Using id you wil be sure that only one element is selected. Also you can assign id and class to one element at once and use each selector accordingly. Remember that styles assigned in id are "more important" as they has priority to class styles if there is a conflict between them (using same styles to the same element). So using right selectors (not randomly) is a good practice, helping to avoid possible problems and extra large CSS file. I advise you keep this in mind when you choose the type of selector.