DEV Community

Discussion on: Stop using so many divs! An intro to semantic HTML

Collapse
 
kenbellows profile image
Ken Bellows • Edited

I hope it does! 😁Though I should say, <div>s are still okay for many purposes, arguably most of the time. I feel like I should write an addendum, with all the attention this post is getting, just to say, "It's fine to use <div>! #NotAllDivs are bad!" The main point is to avoid using a <div> in two cases:

  • When the contents of a block have a specific semantic meaning that has a designated HTML element (<address>, <nav>, <code>, <data>, etc.)
  • When you would add a block to your Table of Contents if you had one, in which case you should use <article> if the block is the root of an entire self-contained piece of content that can be understood on its own (a blog post, news article, forum post, Tweet, Instagram post, etc.), or a <section> if it's only a part of a larger document that wouldn't make sense on its own

If there's no appropriate semantic element, and the block isn't important enough for the TOC, then use a <div>! And if you want to convey more about the semantics than HTML explicitly supports, you can use RDFa or the itemtype attribute and related attribute with a schema.org schema to convey extra info.