When to use a DIV block?

Under what circumstances would you put content in a DIV block as opposed to dropping and positioning it inside a container? Thanks in advance for your help!

Div means Division of page. Containers are divs with special properties. Sections too. Div is the basic bow element in HTML. In HTML5, there are more tags to define them than before. (select a div and look Tag in the Settings tab)

Use a div whenever you need to create a division. Use them to share properties. You could decide to create a “card” with two text elements, a title and a paragraph, giving them not only their font properties but also paddings, backgrounds, borders… but you can also achieve the same result by creating a div for the card, then two divs for the header and content, then place inside a H title and a paragraph. Visually it will be the same but the properties aren’t shared the same way.

Putting things into other things is called Nesting in CSS. It’s not a bad practice, sometimes it’s even recommended.

2 Likes