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 Introduction to HTML and CSS (2016) Getting Familiar with HTML and CSS Building Web Pages with HTML and CSS

Waqas Khan
PLUS
Waqas Khan
Courses Plus Student 2,661 Points

why we use "class element" in html, and what is the purpose of class element?

why we use "class element" in html, and what is the purpose of class element?

2 Answers

Hi Waqas,

I believe you mean class attribute. Class attribute is used to point to a class in your stylesheet. For example, you would give an html element a class when you want to target it with specific css.

Classes can also be used by JavaScript to make changes to HTML elements with that specific class.

Hope this answers your question.

Brent Pfefferle
Brent Pfefferle
3,641 Points

In html, we give an element the class attribute when we want to style more than one element. For example, let's say you have multiple paragraph tags that you want to color blue. If so, assign <p class="blue-paragraph></p> to each paragraph.

Then, in your CSS, you can refer to each paragraph tag with .blue-paragraph.

Overall, it becomes easier to style multiple elements.