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)
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 |
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 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 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.
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:
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.
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 |