Why exactly do we use <div> tags in HTML and when should we use them? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why exactly do we use <div> tags in HTML and when should we use them?

I have just finished learning about HTML in the Web Development Fundamentals course and am not entirely sure of why and when we should use <div> tags within HTML? Thanks for the help

31st Dec 2022, 5:03 PM
Hassanah
Hassanah - avatar
3 Answers
+ 3
The <div> tag defines a division or a section in an HTML document. The <div> tag is used as a container for HTML elements - which is then styled with CSS or manipulated with JavaScript. The <div> tag is easily styled by using the class or id attribute. Any sort of content can be put inside the <div> tag! Note: By default, browsers always place a line break before and after the <div> element.
31st Dec 2022, 5:08 PM
Kyle Clemmer
Kyle Clemmer - avatar
31st Dec 2022, 5:09 PM
Kyle Clemmer
Kyle Clemmer - avatar
+ 1
Thank you Kyle Clemmer! I wasn't really sure of when to use it, but your explanation helped clear a lot of things up for me. Thanks a lot!
31st Dec 2022, 5:11 PM
Hassanah
Hassanah - avatar