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 trialNick Sint
4,208 PointsWhen to use Div vs Section?
Hi everyone,
Quick question, are there general rules of when to use div vs section?
It seems to me that you could use either interchangeably since the purpose of div is essentially to create "sections" within the layout.
3 Answers
Chris Dziewa
17,781 PointsSection usually is used to group content in order to section off parts of your html document for ease of understanding for people reading your code as well as for search engines to consume the site content easier. Section doesn't have as much semantic meaning as the article or aside tags, though they have much more meaning than a div. A div is just a generic container without semantic meaning that can be used for any type of content whether for grouping or not and even just for something such as styling purposes.
If you just need a container for styling, use a div. For more information, check out this article about When to Use the HTML5 SECTION Element
Gabriel Roczanski
Courses Plus Student 2,136 PointsSection: defines a block or group of a specific subject. It is important to understand that section groups several elements that relate to each other. For example, if there is one area in which there are site links, content, images etc of a common subject, you will combine these elements with a section, DIV you use to bring another elements to this section, or just visual, not semantic.
idan ben yair
10,288 PointsHi Nicholas,
You use the SECTION element to define semantically discrete portions of the content, and you use the DIV element as hooks for CSS and JavaScript as well as defining layout that does not have a semantic meaning.
Hope that helped :)