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 trialSandro Meschiari
18,418 Pointsdiv 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
Ryan Duchene
Courses Plus Student 46,022 PointsThere 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 div
s 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
17,351 PointsThe 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!