Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

HTML

Sandro Meschiari
Sandro Meschiari
18,418 Points

div and section

what is the difference between the section and the div? and when can i use them? can i put a div inside of a section or viceversa? Thank you for your help

2 Answers

There is absolutely no difference between the two, except their name. Other elements like section include header, article, footer, main, nav, aside, and probably a couple more that I'm forgetting. Again, these all behave identically to each other and to div; it's just their names that are different.

The different names make reading and understanding HTML a lot easier, because instead of using divs everywhere, we can use nav elements for navigation, or header elements for headers, or aside elements for sidebars or something similar.

You might use section to separate blocks of content from each other. For instance, if I'm working on my blog's homepage, and I want to display my 10 most recent posts there, I might put each post inside its own section. Inside that, I might use a div to display my post title.

Hope that helps!

Charlie Jaime
Charlie Jaime
17,351 Points

The difference between section and div, is that the section tag tends to be used more when you want to divide content within your body type (mostly for organization purposes). A div can also be used for organization, but it has more multi-use purposes. For example, you can isolate content and modify/manipulate it with more ease. Even empty div containers can be used with an html game framework (to create Javascript, create all sorts of games, transitions, just to name a few). Their use is completely up to you. And yes, both can be inserted into one another.

If you like my answer vote me up, or mark me as the best answer. Thank you and great coding!