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.

HTML How to Make a Website Adding Pages to a Website Build the Contact Page

Why was a class used instead of an id tag # for the Contact Details list items?

I thought they both do the same thing (call on an element in your HTML) except class is used when you have multiple instances and id tags are only used for one instance.

3 Answers

Simon Woodard
Simon Woodard
6,545 Points

They do indeed do the same thing in that they identify the object to be styled. However in CSS, an id is given a higher priority than a class.

So you can declare an object to have a class and an id, if you were to assign conflicting styles, the id would win out.

Thanks for this.

Thanks for replying. I had no idea there was any type of prioritization between the two. I'll have to play around with that and see how it works. Thanks Simon!

You completely right here : "I thought they both do the same thing (call on an element in your HTML) except class is used when you have multiple instances and id tags are only used for one instance."

About why a class was used instead of an id, was just about choice.

Thanks for confirming, Aina. I was afraid I was missing something there :)

Chris Malcolm
Chris Malcolm
2,909 Points

Yes agree with aina, its up to the designer to choose what's best. I often like to use classes for more heavily styled elements even if there is only one. And if it is more of something that is for identifiing elements/holding data for access via javascript selector, I will more often use an Id.

Thanks for the advice, Chris. I haven't gotten to javascript or any complicated coding yet, but that's something for me to look forward to once I am making decisions about classes and ids to write better code :)