- Understand the difference between block and inline elements
- Learn when and how to use
<div>and<span> - Practice grouping and organizing HTML content
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 Objectives
<div> and <span>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>
Practice Exercise
Create a page structure with:
<header> with your name<nav> with menu links<main> containing articles<article> elements with content<span> to highlight important words<footer> with copyrightResources & References
Questions?
Week 1 Complete!
Lab 1: Development Environment Setup