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 Build the Contact Page

Jonathan Castillo
PLUS
Jonathan Castillo
Courses Plus Student 836 Points

.Contact-info

On the ul with class="contact-info" why did he use a class instead of an id? is it preference or is that the best practice?

Isaiah McGee
Isaiah McGee
1,378 Points

classes are used when you want to manipulate multiple elements at a time and id's are used when you want to manipulate a single element.

you can have multiple classes but you can only have 1 id

1 Answer

Steven Parker
Steven Parker
231,275 Points

Classes are re-usable, ID's have higher specificity.

As Isaiah mentioned, classes can be used on multiple elements, and an element may have more than one class. But ID's must be unique (per page).

Also, ID's have a higher CSS specificity, which means rules based on them will override rules based on class, no matter where they occur in the cascade. Sometimes this can be desirable, but when it is not it would be another reason to chose classes.