HTML HTML Basics Structuring Your Content Semantic HTML: <header>, <footer> and <section>

Navneet Singh
Navneet Singh
2,424 Points

whay 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> ?

Jason Marlin
Jason Marlin
1,166 Points

I 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....

4 Answers

<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 ids, classes, and anything else to both of them.

Navneet Singh
Navneet Singh
2,424 Points

Thank you for the quick answer :)

this is very enlightening. div always confuses me. section is more appropriate. semantics really is very important.

Vanessa Clifton
Vanessa Clifton
1,349 Points

Thanks had the same question!

thanks. super helpful

Hardik Gami
Hardik Gami
1,622 Points

I had no idea that <div> tag are old, in my present company we still use <div> tags instead of <section> . This was indeed helpfull

Hardik, It's still totally fine to use <div> tags. It's just that there are more options now.