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 trialNavneet Singh
2,424 Pointswhay is the difference between <div> tag and <section> tag.
1). Is this correct below to do,
<div> <section> lorem ipsum </section> </div>
2). Can I give "class" and "id" to the <section> tag instead of <div>.
3). What is the difference between <div> and <section> ?
4 Answers
Eric Butler
33,512 Points<div>
is an old, standard way to contain a set of HTML content inside something. It is still a very popular way to do that.
<section>
was created as part of the HTML5 spec (along with <article>
and a lot of other tags) in an effort to make HTML tags more "semantic." Before, when it was just a ton of <div>
s everywhere, it was difficult for browsers to figure out what the main content and other parts of a webpage were. HTML5 tags attempt to explain what's inside them better.
Bottom line: Functionally, <div>
and <section>
behave exactly the same and you can add id
s, class
es, and anything else to both of them.
Navneet Singh
2,424 PointsThank you for the quick answer :)
web pad
4,483 Pointsthis is very enlightening. div always confuses me. section is more appropriate. semantics really is very important.
Vanessa Clifton
1,415 PointsThanks had the same question!
Syed Shaffizan
471 Pointsthanks. super helpful
Hardik Gami
1,622 PointsI had no idea that <div> tag are old, in my present company we still use <div> tags instead of <section> . This was indeed helpfull
Eric Butler
33,512 PointsHardik, It's still totally fine to use <div>
tags. It's just that there are more options now.
Jason Marlin
1,166 PointsJason Marlin
1,166 PointsI was just about to ask this very same question, glad you asked, and glad they answered. :D ha ha ha, funny though, they called us out. They're like "Div" is for OLD people : P "How do you know about Div....?" I'm like >_> ................. <___< my age is showing....