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

Julian Price
Julian Price
11,760 Points

LETS TALK: Divs Divs & more Divs relation to Best Website Practices

I thought this would be an interesting topic & discussion to see what the overall community comments would be on this topic.

HTML5 tags like the Header, Section, Article & Footer elements so why does everyone still use Div after Div in their mark up.

I have heard often that is Divtis so i love to get the community to weigh in on what Best Website Practices and thinking in Modular approach. I also hope you: Guil Hernandez & Nick Pettit will join the conversation too.

4 Answers

On my side of the fence, I work for a company who still sees a large chunk of revenue from older browsers such as IE7. Obviously HTML5 isn't supported unless we use js to add them. So for support reasons we still use divs. In my personal projects, if the target audience is more future forward, I go with the basic html5 tags but for those that require older browser support, I stick with divs and assign roles to them.

Here's an a good read about the truth behind HTML5 http://www.creativebloq.com/html5/truth-about-structuring-html5-page-9122842

Julian Price
Julian Price
11,760 Points

Thanks Homer Gaines for the insight and the article.

One reason this sort popped up as a conversation because I was looking at GOOGLE site to look at their source code and it too was ALL DIVS.

But I guess Google does not have to worry about their sites getting indexed & found :)

True. There is still a great deal of back and forth as to whether or not HTML5 helps with SEO. Does it help with page structure? Yes, but structure means nothing for SEO if the content is horrible.

Nick Pettit
Nick Pettit
Treehouse Teacher

You shouldn't look at any of Google's source code as an example. They have to optimize code on an absolutely absurd scale, to the point that every line of code counts. They've been known to do things like leave tags unclosed, use tags in a non-semantic fashion, and more, simply because the browser will render it fine and it saves bytes. Multiply this over billions of page views and it adds up to a big cash savings.

Nick Pettit
STAFF
Nick Pettit
Treehouse Teacher

Hi Julian Price,

There's plenty of reasons to use HTML5 technologies. The audio and video elements can replace Flash components, features like viewport are great for mobile, you can create better interactivity with native drag and drop support, and so on. But what about the new elements that have no apparent functional purpose and only seem to be more semantic?

There's two main benefits:

  1. Many semantic HTML5 elements can be made more accessible to screenreaders by utilizing WAI-ARIA roles. This W3C article titled Using WAI-ARIA in HTML contains a table that describes which elements have role attributes that can be definied. Even without roles, it's still a good idea to use these new elements because many screenreaders (present and future) will take advantage of them.
  2. The first item should be reason enough, but using semantic elements has the added benefit of keeping your markup and stylesheets more organized.

There's also a third item that doesn't get mentioned as much. It's impossible for anyone to predict all the future devices and browsers that will become available in the next few years. My guess is that future web browsing experiences will take more advantage of these semantic tags in some way, but it's hard to say how for certain. Still, no harm in supporting those elements now.

Guil Hernandez
STAFF
Guil Hernandez
Treehouse Teacher

Hey Julian Price,

To add to this…The HTML5 technologies are wonderful, and are only getting better with stronger support. While using HTML5 tags may make your markup semantically structured, you still need to make sure that your CSS remains maintainable, predictable, and reusable.

For instance: A selector such as aside header is not reusable––or modular––because it will style any header in an aside. In that case, it might be better to give the header element a modular class like secondary-header. The same can be said for selectors like header nav, section footer, and so forth… It might be best to stick with class names like primary-nav and main-footer – I think those have more meaning than tag selectors.

So, using the HTML5 tags alone as selectors is not recommended, especially on large-scale sites. I still think using divs is perfectly fine, too, as long you plan & execute your architecture well.

Like Nick mentioned, the advantage to using HTML5 tags is that the ARIA roles are already “built in” (for accessibility), and it’s something we should add to important sections of our site where divs are used.

Julian Price
Julian Price
11,760 Points

Thank you Nick Pettit & Guil Hernandez for providing valuable feedback. I am attempting to go a modular approach since my website with become large site and will need to take approach to unsure certain classes are utilized in global variable way.