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

HTML

Can someone please explain me what is the difference between CLASS and ID in html?

2 Answers

Good morning, I had this same question when I was starting on HTML. Both id and class are ways to give a name or identifier to an HTML element, on broader terms classes are used to identify many elements at once, usually for CSS, you can identify all items that you want to style the same way by using and defining the same class. On the other hand id is a more specefic way of category, it can also be used on CSS, but you will often use id to identify elements that are not duplicated on the page, there should not be two ids with the same name, once you start adding animations or transitions through Javascript you will start using ids a lot more.

Ohh now I understand,thanks a lot!

That is a subject that confused me for quite a while. An id is unique, whereas a class can be used on multiple elements. You can only have one id="textfield" in a document, but you can have as many class="textfield" on a document as you want.