Building a complete page
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.
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:
@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:
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
.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:
.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:
.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:
.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:
.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.
Step 8: The footer
.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:
- Resize slowly from 320px to 2000px. Does anything overlap, overflow or look stretched at any width?
- Zoom to 400% at 1280px wide. Is it one column, with no sideways scrolling?
- Keyboard: press Tab through the page. Is focus always visible, never hidden under the sticky header, and in a sensible order?
- Text spacing: apply the WCAG overrides (Layouts that work for everyone). Is any text clipped?
- Font size: set the browser’s default font size to 24px. Do breakpoints and spacing scale?
- Forced colours and dark mode: emulate them in DevTools. Are the card boundaries still visible?
- Real devices: check on an actual phone — browser toolbars, notches and the on-screen keyboard behave differently from DevTools.
- 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-flowand 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.
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.
<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><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>
@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; }
ul[class] { list-style: none; padding: 0; }
}
@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);
}
html { scroll-padding-block-start: 5rem; } /* focus not hidden by the sticky header */
body { font-family: system-ui, sans-serif; line-height: 1.5; }
h1, h2, h3 { line-height: 1.15; }
:focus-visible { outline: 3px solid #2d5bd7; outline-offset: 2px; }
}
@layer layout {
/* (1) Page: stacked, then main + sidebar from 60rem */
body {
min-block-size: 100dvh;
display: grid;
grid-template:
"header" auto
"main" 1fr
"sidebar" auto
"footer" auto
/ minmax(0, 1fr);
gap: var(--space-l) 0;
}
@media (width >= 60rem) {
body {
grid-template:
"header header" auto
"main sidebar" 1fr
"footer footer" auto
/ minmax(0, 1fr) 18rem;
column-gap: var(--space-l);
}
}
.site-header { grid-area: header; }
.main { grid-area: main; }
.sidebar { grid-area: sidebar; }
.site-footer { grid-area: footer; }
.main, .sidebar { padding-inline: var(--space-m); }
.main { display: flex; flex-direction: column; gap: var(--space-m); }
@media (width >= 60rem) {
.main { padding-inline-end: 0; }
.sidebar { padding-inline-start: 0; }
}
}
@layer components {
/* (2) Header */
.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);
padding: var(--space-s) var(--space-m);
background: #16181d;
}
.site-header a { color: white; }
.logo { font-weight: 700; }
.site-header nav { margin-inline-start: auto; }
.nav-links { display: flex; flex-wrap: wrap; gap: 0.25rem var(--space-m); }
.nav-links a { display: inline-flex; align-items: center; min-block-size: 44px; }
@media (height < 30rem) { .site-header { position: static; } }
/* (3) Hero */
.hero { display: grid; gap: var(--space-m); align-items: center; }
@media (width >= 48rem) { .hero { grid-template-columns: 1fr 1fr; } }
.hero-text { display: flex; flex-direction: column; align-items: start; gap: var(--space-s); }
.hero h1 { font-size: clamp(2rem, 1.4rem + 3vw, 3.5rem); }
.hero-img { inline-size: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 12px; }
.cta { display: inline-flex; align-items: center; min-block-size: 44px; padding-inline: 1.25rem; background: #2d5bd7; color: white; border-radius: 8px; }
/* (6) Anchored tooltip */
.info { anchor-name: --info; inline-size: 1.75rem; block-size: 1.75rem; border-radius: 50%; }
#tip {
position-anchor: --info;
inset: auto;
inset-block-start: anchor(bottom);
inset-inline-start: anchor(center);
translate: -50% 0.5rem;
margin: 0;
max-inline-size: min(18rem, 100vw - 2rem);
padding: 0.5rem 0.75rem;
background: #16181d;
color: white;
border: 0;
border-radius: 6px;
position-try-fallbacks: flip-block;
}
/* (4) Course grid with subgrid cards */
.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;
row-gap: var(--space-s);
padding: var(--space-m);
border: 1px solid #d6d6d2;
border-radius: 12px;
position: relative;
}
.course h3 a::after { content: ""; position: absolute; inset: 0; }
.course footer { color: #555; }
/* (5) Sidebar promo with a container query */
.promo-wrap { container: promo / inline-size; }
.promo { display: grid; gap: var(--space-s); padding: var(--space-m); background: #f1ecfd; border-radius: 12px; border: 1px solid transparent; }
.promo img { inline-size: 100%; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 8px; }
@container promo (width >= 24rem) {
.promo { grid-template-columns: 8rem 1fr; align-items: center; }
.promo img { aspect-ratio: 1; }
}
/* (7) Footer */
.site-footer {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
align-items: center;
gap: var(--space-s) var(--space-m);
padding: var(--space-m);
background: #f7f7f5;
}
.footer-links { display: flex; flex-wrap: wrap; gap: var(--space-m); }
.footer-links a { display: inline-flex; align-items: center; min-block-size: 44px; }
}
</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.