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

CSS How to Make a Website CSS: Cascading Style Sheets Use ID Selectors

Nick Sint
Nick Sint
4,208 Points

When 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
Chris Dziewa
17,781 Points

Section 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

Section: 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
idan ben yair
10,288 Points

Hi 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 :)