Coding Now – Best AI & Full Stack Courses in Delhi NCR | 100% Placement
Limited Offer: Get 50% OFF on AI & Full Stack Courses
📞 Call Now: +91 9667708830
Back to HTML Notes
Topic #115

HTML Body Element

The <body> contains everything visible on the page — text, images, forms, everything a visitor actually sees and interacts with.

Example

<body>
    <header>
        <h1>CodingNow</h1>
        <nav>...</nav>
    </header>

    <main>
        <section>
            <h2>Our Courses</h2>
            <p>AI, Data Science, and Full Stack programs.</p>
        </section>
    </main>

    <footer>
        <p>&copy; 2026 CodingNow</p>
    </footer>
</body>

Only One Body Per Document

A valid HTML document has exactly one <body> element — everything visible lives inside it. Multiple <body> tags are invalid; browsers will typically merge their content into the first one, which isn't behavior you should rely on.

Where JavaScript Often Goes

Script tags for page behavior are commonly placed just before the closing </body> tag, so the HTML content loads and renders before the script runs:

<body>
    ...page content...

    <script src="/app.js"></script>
</body>

Modern practice often uses defer in the <head> instead — see defer — but placing scripts at the end of <body> remains a valid, simple approach.

Common Mistakes

  • Adding a second <body> tag by accident when copy-pasting a full page's markup into an existing page
  • Putting <meta> or <title> tags inside <body> instead of <head> — invalid placement, even though some browsers tolerate it

Interview Relevance

Usually tested indirectly, as part of "write a complete HTML document" exercises — knowing exactly what belongs in <head> versus <body> is the practical skill being checked.

Practice Question

Write the <body> for a simple product page with a heading, a product description paragraph, and a "Buy Now" button.

Related HTML Notes

Want to go beyond the notes?

Join CodingNow's HTML course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available
💬 Talk to Advisor
1
WhatsApp

Latest from Our Blog

Insights on AI, Data Science, Full Stack & Career

View All Articles →