Building a complete page

Topic 3 of 3 in Production10 min readBeginnerFree course

Overview

This final lesson brings everything together. You’ll build a complete, responsive landing page for a course site — the kind of page you might ship at work — and use most of the tools from this course along the way. More importantly, you’ll see how to plan a layout like this, so you can approach any design with confidence.

The complete page you’ll build: a sticky flex header; a hero using grid, clamp() type and an object-fit image; a course grid with auto-fit and subgrid cards; a sidebar with a container-query card; and a wrapping flex footer. Checklist: mobile-first with one breakpoint; grid template areas for the page; flexbox for header and footer; fluid type and spacing with clamp(); card grid with auto-fit and subgrid; container query for the sidebar card; sticky header and anchored tooltip; logical properties throughout; passes 400% zoom and keyboard checks.

Step 1: Plan from the outside in

Before writing CSS, look at the design and break it into nested layout decisions. For each box, ask: what layout does it give its children?

Level Box Layout Why
Page body grid with named areas regions in rows and columns
Region .site-header flexbox a row of items, one pushed right
Region .hero grid two equal columns that stack
Component .courses grid, auto-fit unknown number of cards
Component .course subgrid parts line up across cards
Component .promo grid + container query appears in spaces of different widths
Region .site-footer flexbox, wrap rows of links

Then write the HTML in a logical reading order — header, main content, sidebar, footer — with landmarks (<header>, <nav>, <main>, <aside>, <footer>) and lists for lists. Only then start on CSS.

Step 2: Foundations

Start with cascade layers, a reset and tokens, so everything after has a predictable base:

CSS
@layer reset, base, layout, components;

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  * { margin: 0; }
  img { max-inline-size: 100%; block-size: auto; display: block; }
}

@layer base {
  :root {
    --space-s: 0.75rem;
    --space-m: clamp(1rem, 0.8rem + 1vw, 1.5rem);
    --space-l: clamp(1.5rem, 1rem + 2.5vw, 3rem);
  }
  :focus-visible { outline: 3px solid #2d5bd7; outline-offset: 2px; }
}

Step 3: The page grid

Mobile first: one column of areas. From 60rem, add the sidebar column:

CSS
body {
  min-block-size: 100dvh;
  display: grid;
  grid-template: "header" auto "main" 1fr "sidebar" auto "footer" auto / minmax(0, 1fr);
}

@media (width >= 60rem) {
  body {
    grid-template:
      "header header"  auto
      "main   sidebar" 1fr
      "footer footer"  auto
      / minmax(0, 1fr) 18rem;
  }
}

The 1fr row keeps the footer at the bottom on short pages, and minmax(0, 1fr) prevents wide content from blowing out the main column. This is the page’s only media query for layout — everything else adapts by itself.

Step 4: The header

CSS
.site-header {
  position: sticky;
  inset-block-start: 0;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-s) var(--space-m);
}
.site-header nav { margin-inline-start: auto; }
@media (height < 30rem) { .site-header { position: static; } }

Three links fit on a phone, so they simply wrap — no hamburger needed. scroll-padding-block-start on html makes sure keyboard focus and anchor links aren’t hidden behind the sticky header.

Step 5: The hero

A grid that stacks by default and goes side by side when there’s room, with fluid type and a consistently shaped image:

CSS
.hero { display: grid; gap: var(--space-m); align-items: center; }
@media (width >= 48rem) { .hero { grid-template-columns: 1fr 1fr; } }

.hero h1 { font-size: clamp(2rem, 1.4rem + 3vw, 3.5rem); }
.hero-img { inline-size: 100%; aspect-ratio: 4 / 3; object-fit: cover; }

The anchored tooltip

The “?” button opens a popover — the Popover API handles opening, closing on Escape or an outside click, and putting the tooltip in the top layer so nothing can cover it. Anchor positioning places it under the button, and flips it above when there isn’t room below:

CSS
.info { anchor-name: --info; }

#tip {
  position-anchor: --info;
  inset: auto;
  inset-block-start: anchor(bottom);
  inset-inline-start: anchor(center);
  translate: -50% 0.5rem;
  margin: 0;
  position-try-fallbacks: flip-block;
}

inset: auto and margin: 0 clear the browser’s default popover centring. Anchor positioning is supported in all major browsers since January 2026; in older browsers the tooltip still opens — just centred on screen.

Step 6: The course grid

The card-grid recipe from Card grids:

CSS
.courses {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(14rem, 100%), 1fr));
  gap: var(--space-m);
}

.course {
  display: grid;
  grid-row: span 3;
  grid-template-rows: subgrid;
  position: relative;
}
.course h3 a::after { content: ""; position: absolute; inset: 0; }

It works with any number of courses, lines up titles, descriptions and footers across each row, and makes each whole card clickable through a single link.

Step 7: The sidebar promo

The promo card appears in the 18rem sidebar on desktop, and full width under the main content on tablets. A container query lets it adapt to whichever it gets:

CSS
.promo-wrap { container: promo / inline-size; }
.promo { display: grid; gap: var(--space-s); }

@container promo (width >= 24rem) {
  .promo { grid-template-columns: 8rem 1fr; align-items: center; }
}

On a desktop it’s a narrow vertical card; on a tablet, where the sidebar sits below the main content at full width, it becomes a horizontal banner. A media query couldn’t do this, because on a desktop the viewport is wide but the card’s space is narrow.

CSS
.site-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-s) var(--space-m);
}

Step 9: Test like a professional

A layout isn’t finished until it’s tested. Run through this list:

  1. Resize slowly from 320px to 2000px. Does anything overlap, overflow or look stretched at any width?
  2. Zoom to 400% at 1280px wide. Is it one column, with no sideways scrolling?
  3. Keyboard: press Tab through the page. Is focus always visible, never hidden under the sticky header, and in a sensible order?
  4. Text spacing: apply the WCAG overrides (Layouts that work for everyone). Is any text clipped?
  5. Font size: set the browser’s default font size to 24px. Do breakpoints and spacing scale?
  6. Forced colours and dark mode: emulate them in DevTools. Are the card boundaries still visible?
  7. Real devices: check on an actual phone — browser toolbars, notches and the on-screen keyboard behave differently from DevTools.
  8. DevTools overlays: turn on the grid and flex overlays to confirm the structure matches your plan.

Where to go next

You now have a complete toolkit for CSS layout: normal flow, the box model, positioning, flexbox, grid, subgrid, responsive techniques, container queries, anchor positioning, and the accessibility and debugging skills to use them well. A few ways to keep growing:

  • Rebuild real sites. Pick a page you like and recreate its layout from scratch, then compare approaches in DevTools.
  • Build your own primitives. Turn the patterns you use most into a small set of layout classes (stack, cluster, sidebar, auto-grid) and reuse them across projects.
  • Follow new features: CSS grid lanes (masonry), reading-flow and scroll-driven animations are arriving in browsers now.

The big idea of this course: describe relationships — “as many columns as fit”, “the sidebar is 15rem, the content takes the rest”, “this card adapts to its space” — rather than fixed sizes. Layouts built that way work for every screen and every person.

Exercise

The Academy landing page

Build the whole page from the starter HTML, which you shouldn’t need to change. Requirements: (1) the page uses named grid areas — stacked on small screens, with main and a 18rem sidebar side by side from 60rem; (2) a sticky flex header with the logo left and wrapping nav links right; (3) a hero that’s one column on small screens and text + image side by side from 48rem, with clamp() heading and object-fit image; (4) the course list as an auto-fit grid of subgrid cards; (5) the sidebar’s .promo card switches to a horizontal layout when its container is at least 24rem (it never is at 18rem, but it is when stacked on a tablet); (6) the ‘?’ button opens a popover tooltip anchored below it; (7) a wrapping flex footer. Only logical properties for spacing; no horizontal scrolling at 320px.

HTML
<header class="site-header">
  <a class="logo" href="#">Academy</a>
  <nav aria-label="Main"><ul class="nav-links"><li><a href="#">Courses</a></li><li><a href="#">Pricing</a></li><li><a href="#">Blog</a></li></ul></nav>
</header>

<main class="main">
  <section class="hero">
    <div class="hero-text">
      <h1>Master CSS layout</h1>
      <p>From the box model to container queries, with real projects.
        <button class="info" popovertarget="tip" aria-label="About the projects">?</button></p>
      <div id="tip" popover>Every chapter ends with a project you can put in your portfolio.</div>
      <a class="cta" href="#">Start free</a>
    </div>
    <img class="hero-img" width="1200" height="800" alt="A grid layout on a laptop screen" src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='1200' height='800'%3E%3Crect width='1200' height='800' fill='%23c9d8f8'/%3E%3C/svg%3E" />
  </section>

  <h2>Courses</h2>
  <ul class="courses">
    <li class="course"><h3><a href="#">Flexbox</a></h3><p>One-dimensional layout.</p><footer>4h · $19</footer></li>
    <li class="course"><h3><a href="#">Grid from first principles to production</a></h3><p>Two dimensions.</p><footer>6h · $29</footer></li>
    <li class="course"><h3><a href="#">Responsive design</a></h3><p>Media queries, clamp() and container queries.</p><footer>5h · $29</footer></li>
  </ul>
</main>

<aside class="sidebar">
  <div class="promo-wrap">
    <article class="promo"><img alt="" width="300" height="300" src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Crect width='300' height='300' fill='%23e9dffc'/%3E%3C/svg%3E" /><div><h3>Team plans</h3><p>Train your whole team.</p></div></article>
  </div>
</aside>

<footer class="site-footer">
  <p>© Academy</p>
  <ul class="footer-links"><li><a href="#">Privacy</a></li><li><a href="#">Terms</a></li><li><a href="#">Contact</a></li></ul>
</footer>

<style>
  /* Build the page here */
</style>

Summary

  • Plan the page in layers of responsibility: page grid, then regions, then components, then their insides.
  • Use grid for the page and card grids, flexbox for rows of things, and container queries for components that move between regions.
  • Mobile-first with one or two breakpoints, plus intrinsic techniques (auto-fit, clamp, wrapping) for everything else.
  • Keep the HTML in a logical order and test with a keyboard, at 320px and 400% zoom, and with text-spacing overrides.
  • Cascade layers and spacing tokens keep the finished CSS organised as it grows.