<div> help...I'm not sure when to use it?


#1

Hello!

When going through the HTML courses I could put

inside my code line when told to and needed. But I really don’t understand it. I’m not sure when I would use it when creating my own content?

Thanks!


#2

A <div> defines a division or a section of a website. Useful to define different parts of your website which aids to readability of the code. And also extremely useful in combination with CSS style declarations.

For instance if you want a small part of a website to have a different background colour and perhaps some text you can define a div with a class or id name ( <div class="infobox">....</div>) in the html and put the text inside that division.

Then in css you can call for that specific division by its class name and assign style properties such as the color and sizes, but also position on the website.

.infobox {
    background-color: red;
}

But you’ll learn all those things with the CSS courses ;).