After this lecture, students will be able to:
- differentiate block and inline elements
- apply
<div>and<span>in meaningful contexts - organize HTML content using proper grouping
BMC201 - Web Technology
2026-01-29
Lecture 4
HTML Grouping: Div & Span
Week 1 | Unit I: Web Page Designing
BMC201 - Web Technology
Mr. Prashant Kumar Nag, Assistant Professor
Learning Outcomes
After this lecture, students will be able to:
<div> and <span> in meaningful contextsPrerequisites
Syllabus Mapping
Syllabus mapping:
Prerequisites used:
Agenda
Introduction and Motivation
<div> and <span>, styling would have to target individual elements one at a time.Think About It - Interactive Questions
Before we dive into details, think about these:
<p> tag always push to the next line, but a <strong> tag stays within the sentence?Block-level vs Inline Elements
Block-level
<div>, <p>, <h1>Inline
<span>, <a>, <strong>Block vs Inline Visual Difference
Inline 1 Inline 2
The <div> Element
Generic block-level container
<section>, <article>)The <span> Element
Generic inline container
Using <div> for Page Layout
HTML Code:
Visual Result:
Website
<div style="flex: 1; background: #e8f4f8; padding: 10px; border: 1px solid #0088cc;">
<strong>Main Content</strong><br>
<small>This takes up most space</small>
</div>
<div style="width: 120px; background: #fff4e6; padding: 10px; border: 1px solid #ff9800;">
<strong>Posts</strong><br>
<small>Sidebar</small>
</div>
Footer © 2026
Using <span> for Text Styling
HTML & CSS:
Rendered Output:
Price: $99
Call 1-800-HELP
Key Point: Span doesn’t create new lines - it flows inline with text!
Nesting Divs and Spans
HTML Structure:
Rendered Output:
<h2 style="margin: 5px 0;">Web Design Tips</h2>
<span style="font-size: 12px;">Jan 29</span>
<p style="margin: 0;">Keep design <span style="font-weight: bold; color: #ff6b6b;">clean</span></p>
Warning
Nesting is powerful but keep it reasonable (3-4 levels max)
Semantic HTML5 Alternatives
Instead of generic <div>, use semantic elements:
<header> - Page/section header area
<nav> - Navigation links
<main> - Main content area
<section> - Thematic grouping
<article> - Self-contained content
<aside> - Sidebar or supplementary content
<footer> - Page/section footer
Good Semantic Structure
When to Use <div> vs <span>
Use <div>
Use <span>
? Prefer semantic elements when appropriate!
Best Practices for HTML Grouping
Tip
? DO USE: - Semantic HTML5 elements (<header>, <nav>, <article>, <footer>) - Meaningful class names for styling - Reasonable nesting (3-4 levels max) - Proper indentation for readability
Warning
? DON’T USE: - <div> for everything without semantic alternatives - Deeply nested divs (5+ levels) - Generic names like <div class="wrapper"> - Mixed semantic and non-semantic structure
Real-world Example: Blog Post
Semantic HTML:
Visual Rendering:
<span style="font-weight: bold; color: #0088cc;">John</span>
<span style="color: #999; margin-left: 10px; font-size: 12px;">Jan 29</span>
<p style="margin: 0; color: #333;">Web design continuously evolves with new technologies and trends.</p>
Resources & References
Structured Debug Checklist for Div & Span
Investigation order for layout and styling issues:
This approach separates structure issues from styling issues.
Memory Booster: The Container Analogy
Think of your webpage like a shipping warehouse:
<div> = A large shipping box (block container - takes its own shelf space, stacks vertically)<span> = A small label sticker (inline - sticks to the item without claiming extra space)<header>, <nav>, <main> = Named sections of the warehouse (semantic zones)If you use a large shipping box where a label sticker was needed, you waste space. If you use a label sticker where a box was needed, things fall apart!
Live Demo: Div, Span & Container Behavior
Interactive demonstration showing block vs inline behavior and container organization:
?? Open Interactive Demo: HTML Grouping: Div & Span
What you’ll see:
?? Key insight: Choosing containers wisely saves hours of CSS debugging later!
Summary
After this lecture, you should understand:
Exam Preparation Questions: Short
<div> usage.<span> usage.Exam Preparation Questions: Long
<div> and <span> in page design.Practice Task
<div> where needed<span>Checklist
Can you:
Next Lecture
HTML Grouping: Div & Span
Week 1 Complete!
Lab 1: Development Environment Setup