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

<section> vs <div>

Searched around for this, but couldn't find a simple explanation. So far, I've only ever used divs to break up sections of my html. How important is it to begin including the section tag instead? I don't understand the advantage of one over the other.

3 Answers

Andrew Dushane
Andrew Dushane
9,264 Points

This is a good article on the section tag which references the W3C specifications. http://www.impressivewebs.com/html5-section/

Tom Bedford
Tom Bedford
15,645 Points

This chart is very useful for identifying which HTML5 element to use. The different HTML5 elements are used to help add more semantic meaning to your code.

Is it considered bad practice if I use div instead of section (where section would be appropriate)? Unless elements like section and aside are interpreted differently by the browser, I'm still not seeing much benefit in using them. Am I being thick?

Tom Bedford
Tom Bedford
15,645 Points

In modern browsers they will display the same as a div. For older browsers (IE versions 9 and below) you will need to set header, nav, section, aside and footer to display: block; (if you are using normalize or a similar reset they will do this for you).

I don't think it's necessarily bad practice to use divs if you are happier with that. It would be bad to try and force everything into sections/asides if it doesn't make sense to use them. Having a good knowledge of when to use HTML5 elements would be beneficial if HTML is a serious pursuit for you.