</> Code Corner

HTML · HTML Tutorial · Lesson 21

HTML Div

The <div> container element.

The <div> element is used as a container for other HTML elements. It has no required attributes, but style, class and id are common.

Example

<div style="background-color:black;color:white;padding:20px;">
  <h2>London</h2>
  <p>London is the capital city of England.</p>
</div>

Side by side with Flexbox

Example

<div style="display:flex; gap:10px;">
  <div style="background:tomato; padding:20px; flex:1;">London</div>
  <div style="background:gold; padding:20px; flex:1;">Oslo</div>
  <div style="background:skyblue; padding:20px; flex:1;">Rome</div>
</div>

Keep reading “HTML Div”

Sign up to read the full lesson (2 more parts), try every example in the live editor, and take the 5-question quiz.

Chat with us 👋