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

JavaScript Treehouse Club - MASH MASH - HTML Forms/Divs/Input

Johanne Grenier
Johanne Grenier
2,151 Points

Div id VS class

What is the main difference between the id attribute and the class attribute in div elements?

I understand that the id names it, basically we are identifying it and naming it. I'm not sure what class stands for. I understand that it allows us to call them up in CSS. But wouldn't we be able to call them up using their id as well? And if so - when should we use which?

Thanks for asking this Johanne, I was wondering the same thing!

4 Answers

Callum King
seal-mask
.a{fill-rule:evenodd;}techdegree
Callum King
Front End Web Development Techdegree Student 4,934 Points

In a HTML Document, you can only use the same ID on one element, but with classes you can give the same class to multiple elements.

Mandaar Dahale
Mandaar Dahale
2,527 Points

The difference between an ID and a class is that an ID can be used to identify one element, whereas a class can be used to identify more than one. Like class div can be used to group elements together so that they can be easily targeted in css.

ID are more specific than class selector and it will override the element selector and class selector assigned to an element