3 min read · Free · No login needed
The <div> tag is the most used element in web design. It is a generic block-level container: it has no meaning of its own, it adds no styling by itself, and it simply groups other elements together so you can style them or move them as one unit.
Because a div means nothing, use it only when no better tag exists. A page header should be a <header>, a navigation menu a <nav>, the main content a <main>, and an article an <article>. These semantic tags (you will learn them in the Semantics lesson) help search engines and screen readers understand your page. Divs fill in the gaps between them.
A <div> is a generic box. It means nothing by itself — it is simply a container you use to group other elements together so you can style them or move them as one unit. A page is mostly divs: a div for the header, a div for the main content, a div for each card. The div itself adds nothing visible; the CSS you attach to it does the work.
<div class="card"> <h2>HTML Course</h2> <p>Learn HTML from scratch.</p> <a href="course.html">Start learning</a> </div>
Here the div groups a heading, a paragraph, and a link into one card. With one CSS rule for .card, you can give all three a border, padding, and a background at once.
<header>, <nav>, <footer>. Save divs for groups with no better name.class="course-card" or class="sidebar". A class called box1 tells the next person (or you, in three months) nothing.</div> can shift the whole rest of the page.<div style="..."> everywhere instead of giving the div a class once..card { border: 1px solid #ccc; padding: 16px; border-radius: 8px; } — one CSS rule that styles every element with class "card": a light border, padding inside, and rounded corners.<div class="card"> — groups the heading, the paragraph, and the button into one box, so the card's border wraps around all three at once.<h2>HTML Course</h2> and <p>Learn HTML from scratch, free.</p> — the content of the card. They belong to the card, so they sit inside the div.<button>Start Learning</button> — the call to action inside the card. It is part of the same group, so it stays inside the same box.<!DOCTYPE html>
<html>
<head>
<title>Div</title>
<style>
.card { border: 1px solid #ccc; padding: 16px; border-radius: 8px; }
</style>
</head>
<body>
<div class="card">
<h2>HTML Course</h2>
<p>Learn HTML from scratch, free.</p>
<button>Start Learning</button>
</div>
</body>
</html>
Change the code below and press Run to see the result instantly. No file to save, no login needed.
The questions learners ask most about this lesson — read the question, then open it to see the answer.
It is a generic block-level container with no meaning of its own, used to group elements so you can style or move them as one unit.
When a better tag exists, such as header for a page header, nav for navigation, main for main content, or footer for a footer.
A page made only of divs; it works, but it is hard to read and bad for SEO, so use semantic tags for big sections.
AI can write code for you, but it cannot think for you. When you learn HTML yourself, your brain builds the real skill: you understand why a page looks the way it does, you can fix it when it breaks, and you can answer it in an exam or an interview without help. That is the skill that gets you a job — not a copied answer.
Finish all 35 lessons, pass the test (80%), pay ₹10 and get your certificate.
Take the testPrefer watching? Video courses teach the same topics step by step.
Free tutorials teach you the basics. Our paid courses add live projects, mentorship and a certificate.
Browse all coursesAsk about courses, website & more
Request human callback:
Please log in to download. You will stay on this page after logging in!
New here? Register now →