Skip to main content
  1. Data Science Blog/

Exploring HTML Containers - Part 1: Introduction to HTML Containers

·1069 words·6 mins· loading · ·
HTML Web Development Frontend Development HTML Containers HTML5 HTML Structure HTML Page Layout HTML Div Tag HTML Semantic Elements

On This Page

Table of Contents
Share with :

Exploring HTML Containers - Part 1: Introduction to HTML Containers
#

What are different containers in HTML?
#

In HTML and CSS, a “container” tag isn’t a special keyword — it’s a general term used to describe any element that wraps or groups other elements. They don’t of any size of their own, but the size of all the elements put inside the container is their size.

There are several common container tags, each with its own semantic meaning and typical use cases. Here’s a breakdown of the most important ones:

🧱 1. <div>Generic Container
#

  • Use: For grouping elements purely for styling or scripting.
  • Display (default): block
  • Semantics: None (non-semantic)
  • Typical use: Layout blocks, wrappers, utility containers.
<div class="container">
  <h1>Welcome</h1>
  <p>This is a div container.</p>
</div>

✅ Most commonly used container tag.

📰 2. <section>Section of Content
#

  • Use: Groups related content with a heading.
  • Display: block
  • Semantics: Yes — indicates a standalone section.
  • Typical use: Article sections, feature blocks, documentation topics.
<section>
  <h2>Features</h2>
  <p>Some feature content here.</p>
</section>

✅ Use when content has a logical heading and topic.

📝 3. <article>Independent Article Content
#

  • Use: For self-contained content that could be syndicated or reused.
  • Semantics: Yes
  • Typical use: Blog post, news article, forum post.
<article>
  <h2>Blog Title</h2>
  <p>Blog content...</p>
</article>

✅ Use when the content can stand on its own.

📦 4. <main>Main Content Area
#

  • Use: Main unique content of a page (only one per page).
  • Semantics: Yes
  • Typical use: Core article area, excluding sidebars/nav/footers.
<main>
  <h1>Welcome</h1>
  <p>This is the main content.</p>
</main>

✅ Helps screen readers skip to main content.

🎛️ 5. <aside>Side Content
#

  • Use: For tangential or complementary content (ads, tips, related links).
  • Semantics: Yes
  • Typical use: Sidebars, related articles, pull quotes.
<aside>
  <p>Did you know? ...</p>
</aside>

✅ Avoid using for unrelated content.

🧭 6. <nav>Navigation Links#

  • Use: Wraps major navigation links.
  • Semantics: Yes
  • Typical use: Menus, headers, sidebars with links.
<nav>
  <a href="/">Home</a>
  <a href="/about">About</a>
</nav>

✅ Screen readers recognize it as a navigation area.

📜 7. <header> and <footer>Top/Bottom Section Wrappers#

  • Use: Contain intro/outro content.
  • Semantics: Yes
  • Typical use: Inside a page or inside an <article>
<header>
  <h1>My Website</h1>
</header>

<footer>
  <p>© 2025 All rights reserved.</p>
</footer>

✅ Can be used multiple times (e.g., per section or article).

🧃 8. <span>Inline Container
#

  • Use: Group inline content (small sections of text) for styling.
  • Display: inline
  • Semantics: No
  • Typical use: Style part of a sentence.
<p>This is <span class="highlight">important</span> text.</p>

✅ Useful for small inline formatting.

Summary Table
#

TagSemantic?Default DisplayBest Use Case
div❌ NoblockGeneric layout grouping
section✅ YesblockTopical grouping with headings
article✅ YesblockReusable/self-contained content
main✅ YesblockMain content of the page
aside✅ YesblockSidebar/complementary info
nav✅ YesblockNavigation links
header✅ YesblockIntroductory content
footer✅ YesblockClosing content
span❌ NoinlineInline text styling

Why use display: table and related styles instead of HTML <table>?#

Reasons to use table layout with CSS:
#

ReasonExplanation
Semantic HTMLHTML <table> should be used only for tabular data, not for layout. Using div + CSS keeps your HTML semantic and accessible.
Responsive DesignIt’s easier to make layouts responsive when using CSS. HTML tables are rigid and hard to control on small screens.
More Styling ControlWith CSS-based layouts, you have full control over spacing, alignment, media queries, etc.
Cleaner Separation of Content and LayoutYou don’t mix data structure with design intent. That’s modern web practice.

Example:
#

<div class="table">
  <div class="row">
    <div class="cell">Name</div>
    <div class="cell">John</div>
  </div>
  <div class="row">
    <div class="cell">Age</div>
    <div class="cell">30</div>
  </div>
</div>
.table {
  display: table;
}
.row {
  display: table-row;
}
.cell {
  display: table-cell;
  padding: 10px;
  border: 1px solid gray;
}

This creates a layout that looks like a table but uses <div> and CSS instead of HTML <table> elements.

What is displya: grid (CSS grid layout)
#

CSS Grid Layout is a powerful layout system in CSS designed to help web developers create complex and responsive web layouts easily and efficiently. It allows you to create two-dimensional layouts—both rows and columns—without using floats or positioning tricks.

🔷 What is CSS Grid Layout?
#

CSS Grid is a layout model that lets you divide a web page into major regions or define the relationship in terms of size, position, and layer between parts of a control built from HTML primitives.

Think of it as turning your container into a grid of cells, where you can place child elements precisely in any cell or span across multiple cells.

🔧 How CSS Grid Works
#

1. Create a Grid Container
#

You define a grid by setting display: grid on a container.

.container {
  display: grid;
}

2. Define Rows and Columns
#

Use grid-template-columns and grid-template-rows to define the structure.

.container {
  display: grid;
  grid-template-columns: 200px 1fr 1fr;
  grid-template-rows: auto auto;
}

This example creates:

  • 3 columns: one fixed (200px) and two flexible (1fr each)
  • 2 rows with automatic height

3. Place Grid Items
#

Each direct child of the grid container becomes a grid item, and you can control its position using:

.item1 {
  grid-column-start: 1;
  grid-column-end: 3;
  grid-row-start: 1;
  grid-row-end: 2;
}

Or use shorthand:

.item1 {
  grid-area: 1 / 1 / 2 / 3; /* row-start / column-start / row-end / column-end */
}

✅ Key Features of CSS Grid
#

FeatureDescription
display: gridActivates grid layout on a container
grid-template-columns, grid-template-rowsDefines columns and rows
grid-column, grid-rowPlaces items in specific grid areas
fr unitFractional unit for flexible layouts
grid-gap / gapSpace between rows and columns
grid-template-areasName areas and place items semantically

🎯 Use Cases of CSS Grid
#

  • Page Layouts: Headers, sidebars, footers, main content
  • Dashboards: Control panels with resizable sections
  • Galleries: Image grids with consistent spacing
  • Forms: Neatly aligned labels and inputs

🆚 Flexbox vs Grid
#

FeatureFlexboxGrid
Direction1D (row or column)2D (row and column)
Use CaseAlignment, navigation barsLayouts, full-page sections
Item PlacementSequentialAbsolute (by coordinates)

🧠 Visualization Example
#

.container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: auto;
  gap: 10px;
}

HTML:

<div class="container">
  <div class="box">1</div>
  <div class="box">2</div>
  <div class="box">3</div>
</div>

This creates a 3-column layout with equal widths and 10px gaps between boxes.

Dr. Hari Thapliyaal's avatar

Dr. Hari Thapliyaal

Dr. Hari Thapliyal is a seasoned professional and prolific blogger with a multifaceted background that spans the realms of Data Science, Project Management, and Advait-Vedanta Philosophy. Holding a Doctorate in AI/NLP from SSBM (Geneva, Switzerland), Hari has earned Master's degrees in Computers, Business Management, Data Science, and Economics, reflecting his dedication to continuous learning and a diverse skill set. With over three decades of experience in management and leadership, Hari has proven expertise in training, consulting, and coaching within the technology sector. His extensive 16+ years in all phases of software product development are complemented by a decade-long focus on course design, training, coaching, and consulting in Project Management. In the dynamic field of Data Science, Hari stands out with more than three years of hands-on experience in software development, training course development, training, and mentoring professionals. His areas of specialization include Data Science, AI, Computer Vision, NLP, complex machine learning algorithms, statistical modeling, pattern identification, and extraction of valuable insights. Hari's professional journey showcases his diverse experience in planning and executing multiple types of projects. He excels in driving stakeholders to identify and resolve business problems, consistently delivering excellent results. Beyond the professional sphere, Hari finds solace in long meditation, often seeking secluded places or immersing himself in the embrace of nature.

Comments:

Share with :

Related

Exploring CSS Frameworks - A Collection of Lightweight, Responsive, and Themeable Alternatives
·1376 words·7 mins· loading
Web Development Frontend Development CSS Frameworks Lightweight CSS Responsive CSS Themeable CSS CSS Utilities Utility-First CSS
Exploring CSS Frameworks # There are many CSS frameworks and approaches you can use besides …
Dimensions of Software Architecture: Balancing Concerns
·833 words·4 mins· loading
Software Architecture Software Architecture Technical Debt Maintainability Scalability Performance
Dimensions of Software Architecture # Call these “Architectural Concern Categories” or …
Understanding `async`, `await`, and Concurrency in Python
·599 words·3 mins· loading
Python Asyncio Concurrency Synchronous Programming Asynchronous Programming
Understanding async, await, and Concurrency # Understanding async, await, and Concurrency in Python …
High-Level View of HTML CSS JavaScript
·4022 words·19 mins· loading
Web Development HTML CSS JavaScript Web Development Frontend Development
High-Level View of HTML CSS JavaScript # Introduction # HTML, CSS, and JavaScript are the three …
Understanding Vocal Frequencies in Speech-to-Text AI Applications
·4605 words·22 mins· loading
AI NLP Speech-to-Text Vocal Frequencies Sound Signals AI Applications
Exploring Voice Signal Processing # Introduction # In AI projects that involve human voice, such as …