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

Divs

I still don't get what divs are. Can someone help?

1 Answer

brandon downs
brandon downs
11,577 Points

i struggled with this at first too... i have concluded, that a div is an element that is used to "wrap" content. in the same way that the li tag wraps the list content, or the ul tag wraps all of the list items in an unordered list, or how the form tag wraps a form, or even how the body and head tags wrap all of the content inside of the body and head of the document. however, these tags that ive mentioned all have a very specific reason for being used and should not be used for anything else (you wouldnt wrap the list items in a form tag, because its not a form it is a list item) this is called semantic markup. each tag name represents the content that it is wrapping. a div on the other hand, is much more general and can be used in many different places for many different reasons. by giving the div certain class names and id's you can make them more semantic (make more sense in the code as to what they are)

so for example, say you had a small unordered list, and this list had a paragraph that discussed some of the items in greater detail. these two elements are related in a way, they could be wrapped in a div and given a class name or id to give an idea as to their relation.

if anyone else reading this has any corrections, or anything else to add please do. i am still pretty new to all of this and might have some things wrong.

but i hope this helps!

brandon downs
brandon downs
11,577 Points

and of course, the divs can be styled in css to help with the visual representation of their relation

Thank you so much. The comparison between body tags and divs really helped!