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 Customizing Colors and Fonts Organize CSS with Comments

2 Answers

You can have only element with the same id in a page. You can have as many elements as you want with the same class. Or to put it another way, id values have to be unique. So if you have:

<p id="first">...</p>

You can't have another:

<h1 id="first">...</h1>  //first cannot be re-used

But you can do this:

<li class="new">... 
<li class="new">... //new can be re-used
<li class="new">...
<li class="new">...
<li class="new">...
<li class="new">...
<li class="new">...

So use id when the element will be the only one with that value, class otherwise.

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

An id is a unique identifier for an element. Take the id of "main-paragraph". You may not have more than one element on a given page with that particular id. However, a class can be used for multiple elements. For example you could have all paragraphs on your page use the class "generic-paragraph" and then target just one of them with the id of "main-paragraph". IDs are used when we want to specifically target one specific element. Hope that makes sense!