Introduction

Topic 1 of 3 in Getting started6 min readBeginnerFree course

Overview

Every web page is made of boxes: headings, paragraphs, images, buttons, cards, navigation bars. CSS layout is the part of CSS that decides how big each box is and where it goes. Get it right and a page looks polished on a phone, a laptop and a giant monitor. Get it wrong and text overlaps, buttons fall off the screen and users leave.

For years, layout was the hardest part of CSS. Developers bent features designed for other jobs — floats for wrapping text around images, tables for data — into page layouts, with fragile hacks for every browser. Those days are over. Modern CSS has tools built specifically for layout, supported by every current browser:

Tool What it’s for
Normal flow the default: text and blocks stacking naturally
Flexbox arranging items in a row or column
Grid two-dimensional layouts with rows and columns
Positioning taking elements out of the flow: overlays, sticky headers, badges
Container queries components that adapt to the space they’re given
Anchor positioning tooltips and menus tethered to another element

What makes a layout “hold up”

A layout that only works on the designer’s screen isn’t finished. Robust layouts handle:

  • Any screen size — from a 320px-wide phone to a 2560px monitor.
  • Any amount of content — a one-word title or a three-line title, three cards or thirty.
  • Any user setting — a bigger default font size, 400% zoom, a different language or writing direction.

The secret is to describe relationships and limits — “at least this wide”, “share the space equally”, “wrap when there isn’t room” — rather than fixed pixel positions. You’ll practise that mindset throughout the course.

CSS
/* Fragile: breaks on narrow screens and with long titles */
.card {
  width: 300px;
  height: 400px;
  float: left;
}

/* Robust: adapts to space and content */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(16rem, 100%), 1fr));
  gap: 1.5rem;
}

By the end of the Advanced grid chapter, every part of that second example will make sense.

How this course works

Twelve chapters in four stages. Foundations: getting started, the box model, normal flow and positioning. Layout systems: flexbox, grid fundamentals, advanced grid and choosing a tool. Responsive: responsive design and layout patterns. Ship it: accessibility and production.

  1. Foundations — how browsers lay out boxes by default. Most “mysterious” layout bugs are really box-model or normal-flow behaviour.
  2. Layout systems — flexbox and grid in depth, and how to choose between them.
  3. Responsive — media queries, fluid sizing, responsive images, container queries, and the patterns you’ll use on real sites.
  4. Ship it — accessibility, debugging, organising your CSS, and a final project: a complete responsive page.

Each lesson has diagrams, runnable examples and an exercise with a solution.

What you need

  • Basic HTML: elements, attributes, nesting.
  • Basic CSS: how to write a rule (selector { property: value; }), class selectors, and how to link a stylesheet.
  • A code editor and a modern browser (Chrome, Edge, Firefox or Safari).

That’s all. No build tools, no frameworks — layout is pure CSS. Everything you learn works the same in React, Vue, WordPress or a plain HTML file.

Try things as you go

The fastest way to learn layout is to change a value and watch what happens. Keep a scratch file open:

HTML
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Layout playground</title>
    <style>
      * { box-sizing: border-box; }
      body { font-family: system-ui, sans-serif; margin: 0; padding: 2rem; }
      .box { background: #eaf0fc; border: 2px solid #2d5bd7; padding: 1rem; }
    </style>
  </head>
  <body>
    <div class="box">Experiment here</div>
  </body>
</html>

Online playgrounds such as CodePen also work well. And keep your browser’s DevTools open — the lesson Inspecting layout with DevTools shows you the tools that make layout visible.

A mindset to keep: don’t fight the browser. Its defaults are designed to make content readable on any device. The best layouts work with normal flow and add only the rules they need.

Summary

  • CSS layout decides the size and position of every box on a page.
  • Modern CSS — flexbox, grid, container queries, anchor positioning — replaces old float and table hacks.
  • Good layouts are flexible: they adapt to any screen, any content and any user setting.
  • Most layout bugs come from not knowing which layout rules apply — this course makes those rules visible.
  • You only need basic HTML and CSS (selectors, properties, values) to start.