The <div>
element is used to group together other HTML elements. This grouping helps maintain clarity and organisation within the HTML document.
To use a <div>
element, you simply wrap the content or other HTML elements you want to group together within opening <div>
and closing </div>
tags.
In the above example,
- The outermost
<div>
serves as a container, grouping together two inner <div> elements.
- The first inner
<div>
containing a heading <h1>
and a paragraph <p>
acts like an introduction section.
- The second innner
<div>
containing a subheading <h2>
and an unordered list <ul>
acts like a feature section.
The <div>
element only serves as a container without directly changing how output looks or is organised. The <div>
element becomes especially useful when combined with CSS, which you can learn more about in our CSS Course.