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 CSS Basics (2014) Basic Selectors Intro to Selectors

Sergey Pomaraiko
Sergey Pomaraiko
5,572 Points

why we use so many div tags and never section tag?

In this example there is no one section tas. In which case we can use it?

Andrei Duhanes
Andrei Duhanes
14,155 Points

That is a very good question. Not sure if there is a concrete answer but you can get a hint from the thread bellow.


Update: To actually give you an answer of what I think is the reason. Its more easy to use the div for everything than to think and use html Semantically. Although that is not to be encouraged, people are lazy or in a rush and they want to make the html work rapidly, so divs are the most convenient way.

Raymond Turla
Raymond Turla
3,761 Points

I have a follow up question since this is a very interesting topic. In the real-world/industry. Which method should be encouraged? Utilization of semantic tags for better document organization and readability or a div oriented html for developer styling and scripting convenience? I ask this question because i see that most people use div so heavily. I also see some people use section tags but in a different way than the html basics course was taught.

3 Answers

Very good question. Most of the people don't write HTML how it should be written. Section and article tags are semantic elements and they should be used in proper way. So basically div tag should only be used when it's appropriate, when there's is really need for div because any other element doesn't work. Definitely div should not be used in example <div class="nav"><ul><li></li></ul></div> - most of the people write something like this but why use div with class nav when you have <nav> element. You should check out the documentation on using article, section, main, nav, header and footer.

I don't know about HTML Basics course but you should use <div> only when it's appropriate, that means only when anything else doesn't make sense. Maybe it's almost impossible to write everything 100% as it should be but you can get closer to that. Just read MDN page about HTML and semantic elements and you will get a much better understanding. People often use <div> because they are lazy to learn what is the purpose of semantic elements and why is <header> much better than <div class="header">. Most of the people don't know what looks like a well-structured document, it's not hard it just looks for a little more extra effort to learn those practices. <article>

  • The article element represents a component of a page that consists of a self-contained composition in a document, page, application, or site and that is intended to be independently distributable or reusable, e.g. in syndication. <section>
  • represents a standalone section — which doesn't have a more specific semantic element to represent it — contained within an HTML document. Typically, but not always, sections have a heading.