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

Matt Bell
197 PointsThe difference between Div Class And Div ID ?
Hello,
So im a little confused with the difference between div id and div class and wondered if anyone could help and give me a simple explanation so i no when to use each one.
Many Thanks Matt
3 Answers

Jonathan Grieve
Treehouse Moderator 91,254 PointsClasses and ID's are 2 different HTML attributes. They can be applied to any HTML elements, not just divs.
They have multiple purposes but their main purpose is for CSS Styling.
What a class does, is allow you to select an element in CSS more than once and in more than one element type.
<div class="colour"
.colour {
//this is a css class selector
}
An ID is a more like a unique identifier for an element. You can only use an ID once for an element and you can't use that same ID for another element.
<div id="colour"
#colour {
//this is a css ID selector
}
I hope this clears it up for you :)

Matt Bell
197 PointsHey Dane,
Thanks so much that is a clear explanation and i now understand that so i thank you for helping me with that.

Dane Parchment
Treehouse Moderator 11,077 PointsBy div id and div class I am assuming that you are talking about IDs and Classes. Well they both accomplish the same goal of giving an html element a name of sorts that can be used by either other element attributes, css, or some external scripting/programming language. The difference however, is not just semantics but also in how many times they can be used.
An ID, should be unique and as such you can't have 3 divs with the same ID, however, the same class can be used multiple times.
Another difference (though this is only for CSS) has to do with its specificity. An ID has the highest specificity other than that of directly adding the css to an element in html.
Matt Bell
197 PointsMatt Bell
197 PointsWow thanks for that, that really helps i really appreciate you replying back to my question thanks:)