Quesiton: Do you guys have any tips on when to use divs?

I find it a little confusing on when to do it, and I just read about divititus. Wouldn’t want to catch that. XD

Hello! I assume you’re wondering when to use semantic tags vs divs? Personally, I wouldn’t worry too much on not using <divs>, as they can be useful for breaking up the code. A good way to not use too many is to, every time you need to break your code into a chunk (for styling, animation, etc), put <divs> around the code you want to section off, and then see if a better tag would fit (for example, <article>).

Since <div> was designed as a container for code, you should use it for just that; if you need to corner off a piece (or section) of code for something special, but you feel the content still fits with the rest of the page without the special features. If, on the other hand, you feel the code contains content (text, images, etc) that you feel warrant separating from the rest of the text, perhaps look into a semantic tag. Ultimately, it is the content that should dictate whether you use divs or semantic tags, not the need to include semantic HTML (never use semantic tags for the sake of it, there should always be a purpose).

I would highly recommend reading this article on when to use divs.

I hope this helps!

4 Likes

Wow thank you for this! Reading through the article currently. Bookmarked! :grin:

1 Like

No problem! Good luck with future coding!

1 Like