HTML Layout Elements and Techniques: Complete Guide

Learn HTML layout elements and techniques, including header, nav, main, section, article, aside, footer, div, Flexbox, Grid, responsive design, accessibility, and best practices.

HTML Layout Elements and Techniques

HTML layout is the way a webpage is organized into different sections such as the header, navigation menu, main content, sidebars, articles, and footer. A good layout makes a website easier to read, navigate, maintain, and use on different screen sizes.

Modern HTML provides semantic layout elements that describe the purpose of each part of a page. CSS then controls how those elements look and where they appear. Together, HTML and CSS form the foundation of most website layouts.

What Is HTML Layout?

HTML layout refers to the structure and arrangement of content on a web page.

A typical webpage may contain:

  • A header with a logo or website title
  • A navigation area with links
  • A main content section
  • Articles or sections inside the main content
  • A sidebar with related information
  • A footer containing copyright or contact information

A simple layout might look like this:

+--------------------------------------+
|               Header                 |
+--------------------------------------+
| Navigation                           |
+--------------------------------------+
|              |                       |
| Main Content |       Sidebar         |
|              |                       |
+--------------------------------------+
|               Footer                 |
+--------------------------------------+

HTML defines what these areas mean. CSS determines their appearance, size, spacing, and position.

Why Is HTML Layout Important?

A well-structured layout provides several benefits.

Better readability

Content can be divided into meaningful sections, making long pages easier to understand.

Better navigation

Navigation elements help visitors quickly move between different pages or sections.

Better accessibility

Semantic HTML gives browsers and assistive technologies useful information about the structure of a page.

Better SEO

Search engines can better understand the purpose and hierarchy of content when appropriate semantic elements are used.

Easier maintenance

A meaningful structure is easier for developers to read, modify, and debug.

Responsive design

A properly structured HTML document makes it easier to create layouts that work on phones, tablets, laptops, and large screens.

Common HTML Layout Elements

HTML5 introduced several semantic elements specifically useful for page structure.

The most important ones include:

  • <header>
  • <nav>
  • <main>
  • <section>
  • <article>
  • <aside>
  • <footer>

Other elements, such as <div>, <figure>, and <address>, can also be useful depending on the content.

The <header> Element

The <header> element represents introductory content for a page or a particular section.

It commonly contains:

  • Website branding
  • A logo
  • Page titles
  • Introductory text
  • Navigation
  • Search controls

Example:

<header>
  <h1>My Website</h1>
  <p>Learn web development easily.</p>
</header>

A page can have a header, and individual sections or articles can also have their own headers.

For example:

<article>
  <header>
    <h2>Introduction to HTML</h2>
    <p>Published on August 18, 2026</p>
  </header>

  <p>HTML is the standard markup language for creating webpages.</p>
</article>

The <header> element does not automatically create a visual banner. Its appearance is controlled by CSS.

The <nav> Element

The <nav> element represents a major group of navigation links.

Example:

<nav>
  <a href="/">Home</a>
  <a href="/about">About</a>
  <a href="/contact">Contact</a>
</nav>

For a larger navigation menu, lists are often useful:

<nav aria-label="Main navigation">
  <ul>
    <li><a href="/">Home</a></li>
    <li><a href="/articles">Articles</a></li>
    <li><a href="/about">About</a></li>
    <li><a href="/contact">Contact</a></li>
  </ul>
</nav>

The aria-label can help distinguish a navigation landmark when a page contains more than one navigation area.

Not every collection of links needs to be inside <nav>. The element is intended for significant navigation sections.

The <main> Element

The <main> element contains the primary content of a webpage.

Example:

<main>
  <h1>HTML Layout</h1>
  <p>HTML provides semantic elements for organizing webpage content.</p>
</main>

A document should normally have one primary <main> element.

Content that is repeated across pages, such as a global navigation menu, usually does not belong inside <main>.

The <section> Element

The <section> element represents a thematic grouping of content.

A section commonly has a heading.

Example:

<section>
  <h2>HTML Layout Elements</h2>
  <p>HTML provides several semantic elements for webpage structure.</p>
</section>

Sections can help organize a long page into meaningful topics.

For example:

<main>
  <section>
    <h2>Introduction</h2>
    <p>HTML provides the structure of a webpage.</p>
  </section>

  <section>
    <h2>Layout Techniques</h2>
    <p>CSS provides several techniques for arranging HTML elements.</p>
  </section>
</main>

A <section> should generally represent a meaningful thematic grouping rather than simply being used as a generic styling container.

The <article> Element

The <article> element represents a self-contained piece of content that could potentially stand on its own.

Common examples include:

  • Blog posts
  • News stories
  • Forum posts
  • Product reviews
  • Comments
  • Magazine articles

Example:

<article>
  <h2>What Is HTML?</h2>
  <p>HTML is the standard markup language used to structure webpages.</p>
</article>

A page can contain multiple articles:

<main>
  <h1>Latest Articles</h1>

  <article>
    <h2>Introduction to HTML</h2>
    <p>Learn the basic concepts of HTML.</p>
  </article>

  <article>
    <h2>Introduction to CSS</h2>
    <p>Learn how CSS controls the appearance of webpages.</p>
  </article>
</main>

<section> vs <article>

These elements are related but have different purposes.

A <section> groups related content within a larger document.

An <article> represents content that is independently distributable or reusable.

For example:

<section>
  <h2>Technology News</h2>

  <article>
    <h3>New Web Technology</h3>
    <p>Details about the technology...</p>
  </article>

  <article>
    <h3>Browser Updates</h3>
    <p>Details about recent browser changes...</p>
  </article>
</section>

Think of a section as a thematic part of a page and an article as a standalone piece of content.

The <aside> Element

The <aside> element represents content that is related to the surrounding content but is not part of its main flow.

Common uses include:

  • Sidebars
  • Related articles
  • Author information
  • Advertisements
  • Related links
  • Additional notes

Example:

<aside>
  <h2>Related Articles</h2>
  <ul>
    <li><a href="#">HTML Basics</a></li>
    <li><a href="#">CSS Basics</a></li>
  </ul>
</aside>

The exact visual location of an <aside> is not determined by HTML. CSS can place it beside, above, below, or elsewhere in the layout.

The <footer> Element

The <footer> element represents footer information for a page or section.

It may contain:

  • Copyright information
  • Contact information
  • Related links
  • Author information
  • Legal information
  • Social media links

Example:

<footer>
  <p>&copy; 2026 My Website. All rights reserved.</p>
</footer>

Like <header>, a <footer> can belong to the entire webpage or to an individual article or section.

The <div> Element

The <div> element is a generic container.

It has no specific semantic meaning by itself.

Example:

<div class="container">
  <p>Some content goes here.</p>
</div>

It is useful when no semantic HTML element accurately describes the content.

For example:

<div class="card">
  <h2>HTML</h2>
  <p>Learn HTML from the beginning.</p>
</div>

However, developers should avoid replacing meaningful semantic elements with <div> elements unnecessarily.

For example, this:

<div class="header">

may be less meaningful than:

<header>

when the content really represents a header.

Semantic HTML Layout

Semantic HTML means choosing elements based on what the content means rather than simply how it looks.

A semantic layout might be:

<header>
  <h1>My Website</h1>

  <nav>
    <a href="/">Home</a>
    <a href="/blog">Blog</a>
    <a href="/contact">Contact</a>
  </nav>
</header>

<main>
  <article>
    <h2>HTML Layout</h2>
    <p>HTML provides semantic elements for structuring webpages.</p>
  </article>

  <aside>
    <h2>Related Content</h2>
    <p>Explore more HTML tutorials.</p>
  </aside>
</main>

<footer>
  <p>Copyright 2026 My Website</p>
</footer>

This structure is much easier to understand than a page made entirely from generic <div> elements.

HTML Layout and CSS

HTML provides structure, while CSS provides presentation.

For example:

<div class="box">Hello World</div>

CSS can control the appearance:

.box {
  width: 300px;
  padding: 20px;
  margin: 20px;
}

HTML should generally describe the content and its structure. CSS should handle visual presentation.

Important HTML Layout Techniques

There are several ways to create webpage layouts. Modern websites commonly use CSS Flexbox and CSS Grid.

Older techniques include tables and floating elements, but these are generally not the preferred choices for modern page layout.

CSS Flexbox

Flexbox is designed primarily for arranging elements along one dimension: a row or a column.

Example:

<div class="container">
  <div>Home</div>
  <div>About</div>
  <div>Contact</div>
</div>

CSS:

.container {
  display: flex;
  gap: 20px;
}

The elements become flex items and are arranged horizontally by default.

You can also create a vertical layout:

.container {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

Flexbox is particularly useful for:

  • Navigation bars
  • Button groups
  • Toolbars
  • Cards in a row
  • Centering content
  • Aligning items

CSS Grid

CSS Grid is designed for two-dimensional layouts involving rows and columns.

Example:

<div class="layout">
  <header>Header</header>
  <main>Main Content</main>
  <aside>Sidebar</aside>
  <footer>Footer</footer>
</div>

CSS:

.layout {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 20px;
}

Grid is useful for:

  • Complete page layouts
  • Dashboards
  • Card grids
  • Galleries
  • Complex row-and-column structures

Grid Template Areas

CSS Grid allows developers to give areas meaningful names.

Example:

.layout {
  display: grid;
  grid-template-areas:
    "header header"
    "main sidebar"
    "footer footer";

  grid-template-columns: 1fr 300px;
}

header {
  grid-area: header;
}

main {
  grid-area: main;
}

aside {
  grid-area: sidebar;
}

footer {
  grid-area: footer;
}

This makes complex layouts easier to understand and maintain.

Responsive HTML Layout

Modern websites must work on different screen sizes.

A desktop layout might have:

Main Content | Sidebar

On a mobile device, the same content can be arranged as:

Main Content
Sidebar

CSS media queries can help:

.layout {
  display: grid;
  grid-template-columns: 1fr 300px;
}

@media (max-width: 768px) {
  .layout {
    grid-template-columns: 1fr;
  }
}

The HTML structure remains the same while CSS changes the presentation.

Mobile-First Layout

A mobile-first approach starts by designing for smaller screens and then adds styles for larger screens.

Example:

.layout {
  display: block;
}

@media (min-width: 768px) {
  .layout {
    display: grid;
    grid-template-columns: 1fr 300px;
  }
}

This approach can make responsive development easier because the basic layout begins with a simple structure.

The Viewport Meta Element

Responsive websites should normally include the viewport setting in the <head>:

<meta name="viewport" content="width=device-width, initial-scale=1.0">

It helps browsers on mobile devices use the device’s actual viewport width when rendering the page.

Fixed-Width Layouts

A fixed-width layout uses a specific width.

Example:

.container {
  width: 1000px;
  margin: auto;
}

This technique can be problematic on small screens because a fixed width may exceed the available viewport.

Modern responsive designs generally favor flexible dimensions.

Fluid Layouts

A fluid layout uses relative dimensions.

Example:

.container {
  width: 90%;
  margin: auto;
}

The container can expand or shrink according to the available space.

Max-Width Layouts

A common modern approach combines flexible width with a maximum width.

.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
}

This allows the container to use available space while preventing extremely wide lines of content on large screens.

The CSS Box Model

The box model is important when working with HTML layouts.

Every element can be understood in terms of:

  • Content
  • Padding
  • Border
  • Margin

Example:

.card {
  padding: 20px;
  border: 1px solid #ccc;
  margin: 20px;
}

The box-sizing property is often used to make sizing more predictable:

* {
  box-sizing: border-box;
}

With border-box, declared width and height include the element’s padding and border.

Normal Document Flow

By default, HTML elements are laid out according to normal document flow.

Block-level elements generally appear one after another, while inline content flows within a line.

Modern layout systems such as Flexbox and Grid can change how elements are arranged without changing the underlying HTML structure.

HTML Layout with Flexbox Example

A complete example:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Flexbox Layout</title>

  <style>
    .page {
      display: flex;
      flex-wrap: wrap;
      gap: 20px;
    }

    main {
      flex: 1 1 600px;
    }

    aside {
      flex: 0 1 300px;
    }
  </style>
</head>
<body>

  <div class="page">
    <main>
      <h1>Main Content</h1>
      <p>This is the main area of the webpage.</p>
    </main>

    <aside>
      <h2>Sidebar</h2>
      <p>This area contains additional information.</p>
    </aside>
  </div>

</body>
</html>

HTML Layout with Grid Example

Another approach is CSS Grid:

<div class="page">
  <header>Header</header>

  <nav>Navigation</nav>

  <main>
    <h1>Main Content</h1>
    <p>This is the main content area.</p>
  </main>

  <aside>
    <h2>Sidebar</h2>
    <p>Additional information.</p>
  </aside>

  <footer>Footer</footer>
</div>

CSS:

.page {
  display: grid;
  grid-template-areas:
    "header header"
    "nav nav"
    "main aside"
    "footer footer";

  grid-template-columns: 1fr 300px;
  gap: 15px;
}

header {
  grid-area: header;
}

nav {
  grid-area: nav;
}

main {
  grid-area: main;
}

aside {
  grid-area: aside;
}

footer {
  grid-area: footer;
}

A Complete Semantic HTML Layout

A practical HTML5 layout can look like this:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>My Website</title>
</head>

<body>

  <header>
    <h1>My Website</h1>

    <nav aria-label="Main navigation">
      <a href="/">Home</a>
      <a href="/about">About</a>
      <a href="/articles">Articles</a>
      <a href="/contact">Contact</a>
    </nav>
  </header>

  <main>

    <section>
      <h2>Featured Articles</h2>

      <article>
        <h3>Learning HTML</h3>
        <p>HTML provides the structure of webpages.</p>
      </article>

      <article>
        <h3>Learning CSS</h3>
        <p>CSS controls the visual presentation of webpages.</p>
      </article>
    </section>

    <aside>
      <h2>Related Information</h2>
      <p>Explore more web development tutorials.</p>
    </aside>

  </main>

  <footer>
    <p>&copy; 2026 My Website. All rights reserved.</p>
  </footer>

</body>
</html>

Layout Using Tables

HTML tables are designed for tabular data, not general webpage layout.

For example, this is appropriate:

<table>
  <tr>
    <th>Product</th>
    <th>Price</th>
  </tr>
  <tr>
    <td>Book</td>
    <td>$10</td>
  </tr>
</table>

Using tables to create a complete webpage layout is an outdated technique.

For modern layouts, CSS Grid and Flexbox are usually better choices.

Layout Using Floats

The CSS float property was historically used to create multi-column layouts.

Example:

.sidebar {
  float: right;
  width: 30%;
}

.content {
  width: 65%;
}

Floats are still useful for certain content-wrapping situations, such as allowing text to flow around an image, but Flexbox and Grid are generally more suitable for overall page layout.

Positioning in Layouts

CSS provides several positioning methods.

Static

This is the default positioning behavior.

.box {
  position: static;
}

Relative

The element remains in the normal flow but can be visually offset.

.box {
  position: relative;
  top: 10px;
}

Absolute

The element is positioned relative to an appropriate positioned ancestor.

.box {
  position: absolute;
  top: 0;
  right: 0;
}

Fixed

The element is positioned relative to the viewport.

.button {
  position: fixed;
  bottom: 20px;
  right: 20px;
}

Sticky

The element behaves normally until a scrolling threshold is reached.

nav {
  position: sticky;
  top: 0;
}

Positioning can be powerful, but it should not replace normal layout systems when Flexbox or Grid can solve the problem more naturally.

Accessibility and HTML Layout

Good HTML structure is important for accessibility.

Use semantic elements whenever they accurately describe the content.

For example:

<header>
  ...
</header>

<nav>
  ...
</nav>

<main>
  ...
</main>

<aside>
  ...
</aside>

<footer>
  ...
</footer>

This gives browsers and assistive technologies useful structural information.

Use headings properly

Headings should represent the hierarchy of the content.

For example:

<h1>HTML Layout</h1>

<h2>Semantic Elements</h2>
<h3>The Header Element</h3>
<h3>The Footer Element</h3>

<h2>CSS Layout Techniques</h2>
<h3>Flexbox</h3>
<h3>Grid</h3>

Do not choose a heading level simply because it looks larger. CSS should control visual size.

Navigation labels

If there are multiple navigation landmarks, labels can make their purpose clearer:

<nav aria-label="Main navigation">
  ...
</nav>

<nav aria-label="Footer navigation">
  ...
</nav>

SEO and HTML Layout

Semantic structure can help search engines understand webpage content.

A useful structure might include:

<header>
  ...
</header>

<main>
  <article>
    <h1>Page Title</h1>
    ...
  </article>
</main>

<footer>
  ...
</footer>

However, semantic HTML alone does not guarantee higher search rankings. SEO also depends on factors such as useful content, technical quality, accessibility, performance, internal linking, structured data where appropriate, and other search-engine signals.

Common HTML Layout Mistakes

Using <div> for everything

This makes the document harder to understand.

Instead of:

<div class="header">

use:

<header>

when appropriate.

Using tables for page layout

Tables should generally represent data rather than page structure.

Creating unnecessary sections

Not every group of elements needs a <section>.

Choose the element based on meaning.

Ignoring responsive design

A layout that works only on a desktop screen can provide a poor mobile experience.

Using too many absolute positions

Absolute positioning can make a design difficult to maintain and responsive.

Poor heading hierarchy

Avoid jumping between heading levels without a logical reason.

Putting important content only in CSS

HTML should contain meaningful content. CSS should mainly control presentation.

Best Practices for HTML Layout

Follow these principles when building layouts:

  1. Use semantic HTML elements where appropriate.
  2. Keep the HTML structure logical and meaningful.
  3. Use <main> for the primary content.
  4. Use <nav> for important navigation areas.
  5. Use <article> for self-contained content.
  6. Use <section> for meaningful thematic groups.
  7. Use <aside> for related or supplementary content.
  8. Use <header> and <footer> appropriately.
  9. Use <div> when a generic container is actually needed.
  10. Use CSS Flexbox for one-dimensional layouts.
  11. Use CSS Grid for two-dimensional layouts.
  12. Build responsive layouts for different screen sizes.
  13. Avoid tables for page layout.
  14. Avoid unnecessary absolute positioning.
  15. Maintain a logical heading hierarchy.
  16. Consider keyboard and screen-reader users.
  17. Keep content separate from presentation.
  18. Use meaningful class names.
  19. Test layouts at different viewport sizes.
  20. Keep the HTML clean and easy to maintain.

HTML Layout vs CSS Layout

It is important to understand the difference.

HTML describes the structure:

<header>
  <h1>Website Name</h1>
</header>

<main>
  <p>Main content.</p>
</main>

CSS describes the presentation:

header {
  padding: 20px;
}

main {
  max-width: 1000px;
  margin: auto;
}

HTML answers the question, “What is this content?”

CSS answers the question, “How should this content look and be arranged?”

HTML Layout and Responsive Web Design

Responsive design does not require creating a separate HTML page for every device.

A single HTML structure can adapt through CSS.

For example:

.cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
}

@media (max-width: 900px) {
  .cards {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 600px) {
  .cards {
    grid-template-columns: 1fr;
  }
}

This allows three columns on wider screens, two columns on medium screens, and one column on smaller screens.

Layout Elements Are Not Automatically Visual

One important point is that semantic HTML elements do not automatically produce sophisticated layouts.

For example:

<header>Header</header>
<main>Main</main>
<aside>Sidebar</aside>
<footer>Footer</footer>

The browser understands these elements semantically, but CSS is still needed to create a particular visual arrangement.

For example:

main {
  max-width: 900px;
  margin: auto;
}

The HTML describes the structure, while CSS creates the design.

A Simple Mental Model

A useful way to understand modern webpage layout is:

HTML
  ↓
Meaning and structure
  ↓
CSS
  ↓
Layout and visual design
  ↓
Responsive behavior
  ↓
Accessible user interface

HTML is the foundation. CSS is responsible for presentation and layout.

Frequently Asked Questions

What are HTML layout elements?

HTML layout elements are elements used to organize webpage content into meaningful structural areas. Common examples include <header>, <nav>, <main>, <section>, <article>, <aside>, and <footer>.

Which HTML element is used for the main content?

The <main> element represents the primary content of a webpage.

What is the purpose of <header>?

<header> represents introductory content for a page or section. It can contain headings, branding, navigation, introductory information, and other relevant content.

What is the difference between <section> and <div>?

<section> has semantic meaning and represents a thematic grouping of content. <div> is a generic container with no inherent semantic meaning.

What is the difference between <article> and <section>?

An <article> represents self-contained content that can potentially stand alone. A <section> groups related content within a larger document.

What is the purpose of <aside>?

<aside> contains content related to the surrounding content but not part of its primary flow, such as related links, sidebars, or supplementary information.

Should tables be used for HTML page layouts?

Generally, no. Tables are intended for tabular data. Modern webpage layouts should normally use CSS Flexbox, CSS Grid, or other appropriate CSS techniques.

Is <div> still used in modern HTML?

Yes. <div> remains useful as a generic container when no more meaningful semantic element fits the purpose.

Which is better for layout, Flexbox or Grid?

Neither is universally better. Flexbox is especially useful for one-dimensional arrangements, while Grid is particularly useful for two-dimensional row-and-column layouts. They can also be used together.

Can HTML create a responsive layout by itself?

HTML provides the structure, but responsive behavior is primarily controlled with CSS. Media queries, flexible dimensions, Flexbox, and Grid are commonly used to create responsive layouts.

Conclusion

HTML layout is about creating a clear and meaningful structure for webpage content. Modern HTML provides semantic elements such as <header>, <nav>, <main>, <section>, <article>, <aside>, and <footer> to describe different parts of a document.

These elements do not replace CSS. Instead, HTML and CSS work together. HTML provides meaning and structure, while CSS controls positioning, spacing, sizing, colors, typography, and responsive behavior.

For modern websites, semantic HTML combined with CSS Flexbox and CSS Grid provides a powerful and flexible approach to layout. By using meaningful elements, maintaining a logical content hierarchy, designing for different screen sizes, and considering accessibility from the beginning, developers can create websites that are easier to understand, maintain, search, and use.

The key idea is simple: use HTML to describe what the content is, and use CSS to decide how that content should be arranged and presented.

Scroll to Top