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

Hello. I'm confused at what the class attribute is and its function

Hello. I'm confused at what the class attribute is and its function

Doron Geyer
seal-mask
.a{fill-rule:evenodd;}techdegree
Doron Geyer
Full Stack JavaScript Techdegree Student 13,897 Points

Hi Wilfried Allico , in simplest terms the class attribute is just a method of grouping things together so that later if you change styling in your CSS you dont need to do it for each and every element that is the same. So for example you could have a vehicle resale website. If you want all the cars that are sold to have a light red background, you would set their class to "sold" and in your style sheet you would just say

.sold {
    background: red
}

This would set all the cars that are in the "sold" class to a red background. In JavaScript Classes would be a different thing altogether.

1 Answer

Fran ADP
Fran ADP
6,304 Points

The class attribute specifies one or more classnames for an element. The class attribute is mostly used to point to a class in a style sheet. However, it can also be used by a JavaScript to make changes to HTML elements.