Skip to content
Tech Atlas, home
Search
Esc
  • All roadmapsBrowse every learning path
  • ExploreFind a technology area
  • ProjectsGuided projects and builds
  • My AtlasYour learning dashboard
Lesson 5 of 6 · Lab · 30 min · revision 2

Lab: A Product Listing Page Without a Framework

Build a complete product listing page with grid, flexbox and a container query, validate the markup, and verify it at 320, 768, 1280px and 200% zoom.

Contentsand lesson path

What you will learn

  • Build one-dimensional layouts with flexbox: direction, wrapping, gap, alignment and flex-grow, flex-shrink and flex-basis.
  • Build two-dimensional page and component layouts with CSS grid, including named areas, minmax(), auto-fit and subgrid.
  • Adapt layout and type mobile-first with fluid sizing (clamp()), media queries, container queries and responsive images (srcset and sizes), checking Baseline support before using a feature.
  • Verify a layout at 320, 768 and 1280 px widths and at 200% zoom with no horizontal scrolling, clipped text or overlapping content.

Prerequisites: CSS Cascade & Box Model

01. Goal and setup

This lab assembles everything from the previous lessons into one page: a header, a filters panel, a grid of product cards, a featured card that adapts to its own slot, and a footer. No framework, no build step, just HTML and CSS plus two small tools. You will validate the markup before opening a browser, and finish with a measurement script that checks the page at three widths and at 200% zoom, which is exactly the evidence the practice task for this skill asks you to collect.

You need: Node 22 and npm. The install line pins the versions this lab was last run with: Playwright 1.64.1 (Chromium build 1248) and html-validate 11.22.1, on Node v22.23.2. The page needs no real product photos: the width and height attributes reserve each image's space, and the step 5 checks give the same results with the image files missing or replaced by one-pixel placeholders.

The finished folder looks like this:

Project layout
listing/
├── index.html     the page
├── styles.css     all styles, mobile-first
├── measure.mjs    the checks from step 5
├── draft.html     your first markup attempt (step 1)
└── *.png          product photos (optional for this lab)
Terminal
mkdir listing && cd listing
npm init -y
npm install -D [email protected] [email protected]
npx playwright --version
Illustrative output (the package count and the time vary; the last line is exact)
added 15 packages, and audited 16 packages in 5s
found 0 vulnerabilities
Version 1.64.1

Both tools install into the project's own node_modules, never globally. Playwright drives a real Chromium; if npx playwright --version works but the browser itself is missing, run npx playwright install chromium once.

02. Step 1: write the markup and validate it

Write the page in two halves. The head and header give every landmark the page needs: header with the brand and a labelled nav, main for the shop, aside for filters, footer for the small print. The filter checkboxes sit in a fieldset with a legend, and each is wrapped in a label, so the form is usable without guesswork.

HTML · index.html
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Mountain Gear — Shop</title>
    <link rel="stylesheet" href="styles.css">
  </head>
  <body>
    <header class="site-head">
      <p class="brand">Mountain Gear</p>
      <nav class="site-nav" aria-label="Primary">
        <a href="#shop">Shop</a>
        <a href="#orders">Orders</a>
        <a href="#support">Support</a>
      </nav>
    </header>

    <main class="layout" id="shop">
      <aside class="filters" aria-labelledby="filters-title">
        <h2 id="filters-title">Filters</h2>
        <fieldset>
          <legend>Category</legend>
          <label><input type="checkbox" name="tents"> Tents</label>
          <label><input type="checkbox" name="packs"> Packs</label>
          <label><input type="checkbox" name="stoves"> Stoves</label>
        </fieldset>
      </aside>

      <section class="products" aria-label="Products">

The products section holds a full-width featured card inside its own .featured-slot wrapper, then the ordinary grid. Every image carries alt text and width/height attributes, and every card action is a real button. Save the second half to the same file, then create draft.html as a copy with the flask image's alt removed, to see what the validator catches.

HTML · index.html (continued)
        <div class="featured-slot">
          <article class="card featured">
            <img src="stove.png" alt="Two-burner stove" width="640" height="480">
            <div class="card-body">
              <h2>Basecamp stove</h2>
              <p class="price">£89</p>
              <p>Two burners and wind shields for group camps.</p>
              <button type="button">Add to basket</button>
            </div>
          </article>
        </div>

        <div class="grid">
          <article class="card">
            <img src="tent.png" alt="Two-person tunnel tent" width="640" height="480">
            <h2>Tunnel tent</h2>
            <p class="price">£149</p>
            <button type="button">Add to basket</button>
          </article>
          <article class="card">
            <img src="pack.png" alt="45 litre hiking pack" width="640" height="480">
            <h2>Hiking pack</h2>
            <p class="price">£95</p>
            <button type="button">Add to basket</button>
          </article>
          <article class="card">
            <img src="flask.png" alt="One litre steel flask" width="640" height="480">
            <h2>Steel flask</h2>
            <p class="price">£24</p>
            <button type="button">Add to basket</button>
          </article>
          <article class="card">
            <img src="lamp.png" alt="Rechargeable camp lamp" width="640" height="480">
            <h2>Camp lamp</h2>
            <p class="price">£32</p>
            <button type="button">Add to basket</button>
          </article>
          <article class="card">
            <img src="boots.png" alt="Leather walking boots" width="640" height="480">
            <h2>Walking boots</h2>
            <p class="price">£110</p>
            <button type="button">Add to basket</button>
          </article>
        </div>
      </section>
    </main>

    <footer class="site-foot">
      <p>Mountain Gear, Manchester. Prices include VAT.</p>
    </footer>
  </body>
</html>
Terminal
npx html-validate draft.html
npx html-validate index.html && echo "markup ok"
Expected output (the path is absolute, so yours will differ)
/home/you/listing/draft.html
  57:14  error  <img> is missing required "alt" attribute  wcag/h37

✖ 1 problem (1 error, 0 warnings)

More information:
  https://html-validate.org/rules/wcag/h37.html

markup ok

The validator checks the document against the HTML standard and its accessibility rules before any browser is involved; the wcag/h37 rule is the requirement that every img has an alt. A clean run prints nothing and exits 0, which is why the second command appends echo to prove success. Fix the draft by restoring the alt, or delete it and keep index.html as the source of truth.

03. Step 2: the page shell in grid

CSS · styles.css
* {
  box-sizing: border-box;
}

body {
  font: 16px/1.5 system-ui, sans-serif;
  margin: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 100vh;
}

.site-head {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 24px;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-block-end: 1px solid #ddd;
}

.brand {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
}

.site-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.site-nav a {
  padding: 4px 10px;
  border-radius: 6px;
}

.site-nav a:hover {
  background: #eee;
}

.site-nav a:focus-visible,
.card button:focus-visible,
.filters input:focus-visible {
  outline: 2px solid #060;
  outline-offset: 2px;
}

.layout {
  display: grid;
  gap: 16px;
  padding: 16px;
  align-items: start;
}

@media (min-width: 48em) {
  .layout {
    grid-template-columns: 240px 1fr;
  }
}

The body is itself a grid whose three rows are header, main, footer, with 1fr giving the main area the spare height. The header row uses flexbox with flex-wrap: wrap, so a narrow phone moves the nav under the brand instead of squeezing it. The .layout main area starts as a single column, filters above products, and gains a 240px filters column from 48em, the mobile-first pattern from the fluid layouts lesson. Logical properties such as border-block-end keep the borders correct if the page is ever translated into a language that runs top to bottom differently.

04. Step 3: the card grid and the cards inside it

CSS · styles.css
.filters {
  border: 1px solid #ddd;
  border-radius: 12px;
  padding: 12px 16px;
}

.filters h2 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.filters fieldset {
  border: 0;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 4px;
}

.filters legend {
  font-weight: 600;
  padding: 0;
}

.products {
  display: grid;
  gap: 16px;
}

.grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
}

.card {
  border: 1px solid #ddd;
  border-radius: 12px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.card img {
  width: 100%;
  height: auto;
  border-radius: 8px;
}

.card h2 {
  margin: 0;
  font-size: 1.125rem;
}

.card .price {
  margin: 0;
  font-weight: 700;
}

.card p {
  margin: 0;
}

.card button {
  margin-block-start: auto;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid #999;
  background: #f4f4f4;
  font: inherit;
}

.card button:hover {
  background: #e8e8e8;
}

.site-foot {
  padding: 12px 16px;
  border-block-start: 1px solid #ddd;
}

.site-foot p {
  margin: 0;
}

The product grid is the auto-fill pattern from the grid lesson: as many columns of at least 210px as fit, all stretched to share the row. Because .grid cards stretch to equal height in each row by default (align-items: stretch), each card gets full row height. Each card is a flex column, and margin-block-start: auto on the button pushes it to the bottom of its card, so buttons line up neatly on each row even when descriptions differ in length. width: 100% with height: auto lets the images shrink with their card instead of overflowing it, which is one of the two usual causes of sideways scrolling at 320px.

06. Step 5: verify at three widths and 200% zoom

The final objective of this skill is evidence, not vibes. The script below visits the page at 320, 768 and 1280px, then emulates a 1280px window at 200% browser zoom, which behaves like a 640px viewport with every CSS pixel drawn twice (deviceScaleFactor: 2). At each size it reports the page width against the viewport, the computed column count, where the filters sit, which mode the featured card chose, and a handful of accessibility counts. A last line compares every element's text size on screen, its computed size × devicePixelRatio, at 200% zoom with the same element at 1280px.

JavaScript · measure.mjs
import { chromium } from 'playwright';
import { pathToFileURL } from 'node:url';

const browser = await chromium.launch();
const url = pathToFileURL('index.html').href;

const audit = async (label, page) => {
  const data = await page.evaluate(() => {
    const doc = document.documentElement;
    const grid = getComputedStyle(document.querySelector('.grid'));
    const columns = grid.gridTemplateColumns
      .split(' ')
      .filter((v) => v !== '0px').length;
    const filters = document.querySelector('.filters').getBoundingClientRect();
    const products = document.querySelector('.grid').getBoundingClientRect();
    const featured = getComputedStyle(document.querySelector('.featured'));
    const featuredMode = featured.display === 'grid' ? 'side by side' : 'stacked';
    const overflowing = [...document.querySelectorAll('body *')].filter(
      (el) => el.getBoundingClientRect().right > window.innerWidth + 1,
    ).length;
    const missingAlt = [...document.images].filter((img) => !img.alt.trim()).length;
    const unnamed = [...document.querySelectorAll('button, a')].filter(
      (el) => !(el.textContent.trim() || el.getAttribute('aria-label')),
    ).length;
    const landmarks = ['header', 'nav', 'main', 'footer'].filter(
      (tag) => document.querySelector(tag),
    ).length;
    return {
      pageW: doc.scrollWidth,
      viewW: window.innerWidth,
      columns,
      beside: products.x > filters.x + filters.width,
      featuredMode,
      overflowing,
      missingAlt,
      unnamed,
      landmarks,
    };
  });
  const side = data.beside ? 'beside' : 'above';
  console.log(
    `${label}: page ${data.pageW}/${data.viewW}px, grid columns ${data.columns}, ` +
      `filters ${side} products,`,
  );
  console.log(
    `    featured card ${data.featuredMode}, overflowing elements ${data.overflowing},`,
  );
  console.log(
    `    images without alt ${data.missingAlt}, unnamed controls ${data.unnamed}, ` +
      `landmarks ${data.landmarks}/4`,
  );
};

const page = await browser.newPage();
for (const width of [320, 768, 1280]) {
  await page.setViewportSize({ width, height: 900 });
  await page.goto(url);
  await audit(`${width}px viewport      `, page);
}

const zoomed = await browser.newPage({ deviceScaleFactor: 2 });
await zoomed.setViewportSize({ width: 640, height: 900 });
await zoomed.goto(url);
await audit('200% zoom (640px) ', zoomed);

// Text check: every element should be drawn twice as large as at 1280px, 100%.
const onScreen = (p) =>
  p.$$eval('body *', (els) =>
    els.map((el) => parseFloat(getComputedStyle(el).fontSize) * devicePixelRatio));
const [at100, at200] = [await onScreen(page), await onScreen(zoomed)];
const least = Math.min(...at200.map((size, i) => size / at100[i]));
console.log(`200% zoom text check: smallest growth ${least.toFixed(2)}x`);
await browser.close();
Terminal
node measure.mjs
Expected output (Chromium 156 via Playwright 1.64.1)
320px viewport      : page 320/320px, grid columns 1, filters above products,
    featured card stacked, overflowing elements 0,
    images without alt 0, unnamed controls 0, landmarks 4/4
768px viewport      : page 768/768px, grid columns 2, filters beside products,
    featured card side by side, overflowing elements 0,
    images without alt 0, unnamed controls 0, landmarks 4/4
1280px viewport      : page 1280/1280px, grid columns 4, filters beside products,
    featured card side by side, overflowing elements 0,
    images without alt 0, unnamed controls 0, landmarks 4/4
200% zoom (640px) : page 640/640px, grid columns 2, filters above products,
    featured card side by side, overflowing elements 0,
    images without alt 0, unnamed controls 0, landmarks 4/4
200% zoom text check: smallest growth 2.00x

Read the lines as five claims. Page width equals viewport width and no element sticks out at any size, so nothing scrolls sideways, including under 200% zoom. The grid reflows from one column to two to four without a single breakpoint of its own. The filters move from above to beside the products exactly at the 48em breakpoint (768px, where the two-column layout has just enough room). And the featured card switches on its container: stacked at 320px where its slot is 288px, side by side from 768px up, and still side by side under zoom because its slot there is 608px. The last line shows that every piece of text doubled, because the page sizes text in rem and px. That is the WCAG 1.4.4 Resize Text check from the fluid type lesson: when the same lab was run with .brand { font-size: clamp(1rem, 0.5rem + 5vw, 6rem); } added, the line read 1.11x. The accessibility counts are the page's own sanity check, not a substitute for testing with a screen reader or an axe audit.

07. Check your understanding

Practice check · 3 questions

Reading the evidence

Reason from the measured output above.

Q1. The featured card renders stacked at 320px and side by side at 768px. What decides the switch?
Q2. The text check multiplies each computed font size by `devicePixelRatio` before comparing the 200% zoom page with the 1280px page. Why?
Q3. html-validate reported a missing `alt` before the page ever reached a browser test. Why validate the markup at all?
Practice only: not graded, not saved, not evidence.

08. Apply it: extend the lab

The practice task for this skill asks for screenshots of a product listing at 320, 768 and 1280px and at 200% zoom. Finish the job properly:

  1. Take a screenshot at each of the four sizes above (page.screenshot({ path, fullPage: true }) in the same script), and keep them with your notes.
  2. Replace two placeholder images with real photos of different widths and add srcset with sizes that matches the card widths you measured.
  3. Add one more product row that must line up its buttons across cards using subgrid, and extend the script to assert the shared y coordinate.
  4. Re-run the validator and the measurement script after every change; both should stay clean before you submit the evidence.

09. Review prompt

Without looking back: which parts of the page use grid, which use flexbox, and why does each suit its job? What does the 48em media query change, and what does the 480px container query change instead? Why does margin-block-start: auto line the buttons up, and which two measurements in the output prove there is no sideways scrolling? What does deviceScaleFactor: 2 at a 640px viewport emulate, and what does the text check prove?

References

Your progress

Reading state

Sign in to save that you finished reading this lesson.

Sign in to mark reading complete

Prove this skill

8 questions · about 6 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.
Take the skill check