HTML Layout


Lesson 36 of 58

Websites often display content in multiple columns, just like a magazine or newspaper. A typical webpage has a header, navigation menu, main content area, sidebar, and a footer.


HTML Layout Elements

HTML5 introduced semantic elements that clearly describe their meaning to both the browser and the developer. Here are the most important ones:

  • <header> – Top of the page (logo, title, tagline)
  • <nav> – Navigation links (menu)
  • <section> – A group of related content
  • <article> – Self-contained content (like a blog post)
  • <aside> – Sidebar content (related but not essential)
  • <footer> – Bottom of the page (copyright, contact info)
Basic HTML Layout Example

Layout Techniques Overview

There are four main ways to create multi-column layouts. Each has its own strengths:

Technique Best For Difficulty
CSS Frameworks Quick prototyping, beginners Easy
CSS Float Simple layouts, older browser support Medium
CSS Flexbox One-dimensional layouts (rows or columns) Medium
CSS Grid Two-dimensional layouts (rows and columns) Advanced
Tip: For beginners, start with Flexbox. It is modern, powerful, and easier to understand than float layouts.

Method 1: CSS Flexbox (Recommended for Beginners)

Flexbox is a modern CSS layout method. It makes aligning items in rows or columns very easy.

Flexbox Layout Example

Flexbox is great for navigation bars, card layouts, and simple column structures.


Method 2: CSS Grid (For Complex Layouts)

CSS Grid is even more powerful than Flexbox. It lets you control both rows and columns at the same time.

Grid Layout Example

Grid is perfect for complex layouts where you need precise control over rows and columns.


Method 3: CSS Float (Old Way)

The float property was used for layouts before Flexbox and Grid existed. It still works, but Flexbox and Grid are better choices for new projects.

Float Layout Example

Notice the clear: both; on the footer. This is needed to stop the footer from floating up next to the columns.


Complete Magazine-Style Layout

Here is a complete example of a magazine-style webpage with header, navigation, content, sidebar, and footer:

Magazine Layout Example

Quick Summary

  • Use semantic HTML elements: <header>, <nav>, <section>, <article>, <aside>, <footer>.
  • Flexbox is best for one-dimensional layouts (rows or columns).
  • CSS Grid is best for two-dimensional layouts (rows AND columns).
  • Float layouts work but are outdated. Use Flexbox or Grid for new projects.
  • Always make your layout responsive with media queries so it works on mobile.
  • Test your layout on different screen sizes (desktop, tablet, phone).

What Just Happened? Let Me Explain

  • Semantic HTML elements help search engines and screen readers understand your page structure.
  • Flexbox is like arranging items in a row or column. You can easily change their order and spacing.
  • CSS Grid is like creating a table where you decide how many rows and columns you want.
  • Media queries are what make layouts responsive. They apply different CSS rules for different screen sizes.
  • Do not worry about memorizing everything. You will learn more CSS layout techniques in the CSS tutorial.
Tip: Open VS Code and create a file called layout.html. Build a simple page with a header, navigation, two columns (main content and sidebar), and a footer. Use Flexbox to make the columns side by side on desktop and stacked on mobile. This is exactly how real websites are built.

HTML Layout Reference

Here are the semantic layout elements we covered:

Tag Description
<header> Defines a header for a document or section
<nav> Defines a set of navigation links
<section> Defines a section in a document
<article> Defines independent, self-contained content
<aside> Defines content aside from the main content (sidebar)
<footer> Defines a footer for a document or section

Lesson 36 of 58