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
susan reichmann
2,224 PointsWhat is the difference between class and element selectors?
What is the difference between class and element selectors?
1 Answer
Ken Alger
Treehouse TeacherSusan;
Great question. HTML elements are things like <h1>, <p>, <div>, <nav>, etc. They are the building blocks of the page. Classes are names/conventions the developer includes that will go inside the angle brackets of an element and allow for more specific, or general styling in CSS or functionality in JavaScript.
You can do some similar things with both, but adding classes to elements allows for more granular control.
For example:
<p>Some Text</p>
<p>Some More Text</p>
<p class="last_line">The last line of text</p>
In CSS you can target all <p> elements to style them or you could just style the one with the class "last_line". This is a general overview as you can do much more with CSS and pick and choose which <p> elements to target in this example, but the example is just for simplicity.
Post back with additional questions.
Happy coding,
Ken
susan reichmann
2,224 Pointssusan reichmann
2,224 PointsThanks!