Build Your Own Web

Build this website with blocks

Try another way to build: snap together HTML, CSS and behavior blocks, change their fields, and watch your website update. Start with this lesson’s project or try a code example below.

Want to keep what you build? Web Studio holds a drawing, blocks and code in one project that you can share on the class site and publish as your own website.

Lesson 3 of the pathway · 55–75 minutes · You need the folder and the HTML from Lessons 1 and 2

Design with CSS

HTML says what your page means. CSS says what it looks like. In this lesson you set spacing, type and color once, then let a grid arrange your project cards at any screen size.

Work in style.css. Save, then refresh the browser after every change. If nothing happens, check that index.html still contains <link rel="stylesheet" href="style.css"> inside its <head>.

A rule has three parts

Every CSS rule points at some elements and changes some of their properties.

h1 {              /* selector: which elements */
  color: #14243d; /* property: value; */
  margin-bottom: 8px;
}

You only need four kinds of selector to build a real site. Learn these, and add more later when you actually need them.

The four selectors that do most of the work
SelectorMatchesUse it for
pEvery paragraph on the pageSite-wide defaults: type, color, spacing
.cardElements with class="card"Anything you repeat — this is your main tool
#contactThe one element with id="contact"A single unique thing, usually a link target
.card h3Headings inside a cardStyling parts of a component

When two rules disagree

Sometimes the browser ignores a rule you wrote. It is rarely broken; usually another rule won because the browser scores selectors using a strict specificity algorithm: an id beats a class, because an id identifies a single unique entity on the page, whereas a class targets a reusable category, which in turn outweighs a generic element tag. When two rules score identically, the browser applies the later one in cascade order. Therefore, adding an id or an !important flag creates an artificial arms race; this means you should style with classes so that rules remain predictable and maintainable.

p        { color: gray; }   /* score: element */
.intro   { color: navy; }   /* score: class — this one wins */

The rule to live by: style with classes. Reach for ids and long selector chains only when a class genuinely cannot do the job. Never use !important to win an argument you can win by deleting the rule that conflicts.

Investigation: which elements does a selector reach?

Predict first: say which cards the selector should match. Then choose it and reveal the browser’s answer. The highlighted cards are the elements the rule is allowed to style.

class="card"

North star

First project card.

class="card"

Trail map

Third project card.

Choose a selector after making your prediction.

Notice the difference between .card h3 and h3: the space means “an h3 somewhere inside an element with class card.”

Every element is a box

Point at any element on your page and the browser is drawing four nested layers around it: the content, then padding inside the border, then the border, then margin as empty space outside it.

.card {
  padding: 16px;                 /* space inside the border */
  border: 1px solid #c6d0df;     /* the line itself */
  margin-bottom: 16px;           /* space pushing other things away */
}

The reason this difference matters is the box model calculation: under the historical default box-sizing: content-box, the browser calculates total rendered width as width + padding-left + padding-right + border-left + border-right. Therefore, setting a box to width: 100% while adding 16px padding causes the element to expand to 100% + 32px, which pushes the container beyond the viewport and triggers horizontal scrolling. Adding box-sizing: border-box changes the calculation so that padding and borders are absorbed inside the declared width, which means a 300px box remains strictly 300px on screen.

Add this one rule at the top of every stylesheet you ever write:

*, *::before, *::after { box-sizing: border-box; }

Because this rule overrides the legacy calculation across all elements and pseudo-elements, the exact width you specify in your layout is the exact footprint the browser draws on the page.

Investigation: feel the four layers

Change one layer at a time. Padding grows the coloured box; margin grows the space around it. The measured footprint below counts the content, padding and border—not the outside margin.

contentthe content box

Reconstruction of Johannes Gutenberg's wooden hand printing press showing the bed, platen, and lever
Gutenberg Hand Press (The Mechanical Ancestor of Page Layout) Johannes Gutenberg's 15th-century press locked lines of movable type into a rigid iron chase. Surrounding wooden furniture and lead slugs created the outer margins and gutter spacing. The CSS Box Model (content, padding, border, and margin) formalizes this exact physical geometry into digital browser rendering. Credit: Gutenberg Museum / Wikimedia Commons · Public domain · source
Lead movable type sorts arranged in a composing stick showing physical typographical spacing
Movable Type Sorts and the Physical Box Model Each individual metal letter sort possesses physical dimensions: the raised typeface (content box), the shoulder around the character (padding), and the outer cast body (margin/border bounding box). Setting box-sizing: border-box ensures digital containers behave with predictable physical edges rather than expanding uncontrollably. Credit: Willi Heidelbach / Wikimedia Commons · CC BY-SA 3.0 · source

Design tokens: Spacing, colors & dark mode themes

Beginner pages look untidy for one boring reason: the spacing is 13px here, 7px there, 22px somewhere else. Professional pages use one small set of numbers and colors everywhere. Store them once as custom properties (CSS variables):

:root {
  /* Spacing Scale */
  --space-sm: 8px;
  --space: 16px;
  --space-lg: 32px;
  --radius: 10px;

  /* Light Theme (Default) */
  --paper: #ffffff;
  --surface: #f8fafc;
  --ink: #0f172a;
  --ink-muted: #64748b;
  --line: #cbd5e1;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
}

/* Dark Theme: One small rule switches the entire palette */
body.dark-theme, [data-theme="dark"] {
  --paper: #0f172a;
  --surface: #1e293b;
  --ink: #f8fafc;
  --ink-muted: #94a3b8;
  --line: #334155;
  --accent: #60a5fa;
  --accent-hover: #93c5fd;
}

.card {
  background: var(--surface);
  color: var(--ink);
  padding: var(--space);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
section { margin-bottom: var(--space-lg); }
a { color: var(--accent); }

A custom property is a name you invent, starting with two dashes (--), that holds a value; declaring it on :root makes it available to the entire document. Notice how changing the theme requires zero edits to your card or section rules — they automatically read whatever values the current theme provides!

Color formats decoded

Modern CSS supports three main ways to express colors:

Type people can actually read

Three settings do most of the work: size, line height, and line length.

body {
  font-family: system-ui, Arial, sans-serif;
  font-size: 18px;
  line-height: 1.6;      /* 1.6 × the font size */
}
p { max-width: 65ch; }   /* about 65 characters per line */

Line height under about 1.4 feels cramped, and a line running the full width of a wide monitor is genuinely hard to read: your eye loses its place coming back to the left edge. The ch unit is the width of a zero in the current font, so 65ch is roughly the measure a book uses.

Headings need a scale, not random sizes. Pick three or four steps and stop: for example 2rem, 1.5rem, 1.25rem. Keep the same font family for everything until the rest of the site works.

Portrait of Håkon Wium Lie, the creator of Cascading Style Sheets (CSS)
Håkon Wium Lie (Inventor of CSS) Norwegian computer scientist Håkon Wium Lie proposed Cascading Style Sheets (CSS) in October 1994 while working at CERN with Tim Berners-Lee. Lie argued that web presentation should be cleanly separated from document structure, creating a cascading language that balances author designs with reader preferences, screen sizes, and accessible contrast. Credit: Jarle Vines / Wikimedia Commons · CC BY-SA 3.0 · source
William Caslon's 1734 broadsheet type specimen displaying fonts arranged by scale and weight
William Caslon's Type Specimen Sheet (1734) The gold standard of typographic hierarchy. Caslon organized fonts into disciplined proportional scales (Five-Line Pica, Double Pica, Great Primer, English, Long Primer, Brevier). In modern CSS, we implement this exact harmonic progression using modular rem units, font-weight, and balanced line-height ratios for optimal reading rhythm. Credit: William Caslon / Wikimedia Commons · Public domain · source

Color, and the contrast check you owe your reader

Text must stand out from what is behind it: at least a 4.5 to 1 contrast ratio for normal text. Light gray on white fails. You cannot judge this by eye on a bright screen, so check it.

  1. Open your page, right-click your body text and choose Inspect.
  2. Find the color value in the Styles panel and click its color swatch.
  3. Chrome and Firefox show the contrast ratio against the background. Aim for 4.5 or higher.

Also: never use color as the only signal. If your "sold out" cards are just red, a reader who cannot distinguish red from green learns nothing. Add a word, an icon, or a border as well.

Finally, make focus visible. Keyboard users need to see where they are:

:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
Albert Henry Munsell's 1900 color sphere showing hue, value, and chroma coordinates
Albert Munsell's Color Solid (1900) The scientific basis of perceptual color models. Munsell organized color across three independent perceptual axes: Hue (color family), Value (lightness from black to white), and Chroma (purity/saturation). Modern CSS variables, HSL/OKLCH color coordinates, and WCAG contrast algorithms rely directly on this three-dimensional model to calculate accessible luminance ratios. Credit: Albert H. Munsell / Library of Congress / Wikimedia Commons · Public domain · source
Sir Isaac Newton's original circular diagram of color spectrum relationships from Opticks (1704)
Isaac Newton's Spectrum Circle (Opticks, 1704) Sir Isaac Newton's original circular arrangement of primary and secondary colors. By closing the visible light spectrum into a circle, Newton established the mathematical foundation of complementary color pairs. Web designers use complementary pairs on opposite sides of the circle to achieve crisp, accessible contrast between buttons and backgrounds. Credit: Isaac Newton / Royal Society / Wikimedia Commons · Public domain · source

Flexbox: a row of things

Flexbox lays items out along a single flexible dimension (the main axis) and distributes remaining space among them. This means items adjust based on their intrinsic content sizes, and wrapping creates independent, uncoordinated lines. Therefore, Flexbox is the ideal tool for a navigation bar, a row of buttons, or a header with a title on the left and links on the right.

.site-nav {
  display: flex;             /* children become a row */
  gap: var(--space);         /* space between them */
  align-items: center;       /* line them up vertically */
  flex-wrap: wrap;           /* let them drop to a new line if narrow */
}

Add justify-content: space-between; and the first child hugs the left edge while the last hugs the right. Leave flex-wrap: wrap on, or a narrow phone squashes your links instead of stacking them.

Flexbox alignment cheat sheet
PropertyCommon valuesVisual effect
justify-content (Main Axis)flex-start | center | space-betweenPushes items to the left, groups them in the center, or spreads them evenly from edge to edge.
align-items (Cross Axis)center | stretch | flex-startCenters items vertically, stretches them to matching heights, or aligns tops.
gap16px | var(--space)Gives items breathing room without messy margin calculations.

Grid: a layout of cards

Flexbox arranges one line. Grid arranges rows and columns at the same time into a cohesive two-dimensional coordinate system. Because Grid tracks intersect across the entire container, cards in row two strictly align with cards in row one, even when their internal text heights vary. Three properties do it:

.cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space);
}

1fr means "one share of the free space", so three of them make three equal columns. minmax(0, 1fr) is the safe version: because grid items by default have a minimum size of auto, a long unbroken word or preformatted string can force a bare 1fr column to expand wider than intended, which causes horizontal page overflow. Setting the minimum to 0 allows the column to shrink and wrap text cleanly instead of breaking your layout.

Draw a grid instead of typing one. Web Studio’s Draw mode lays every page on 12 columns. Drag a box across columns 1–8 and its rule says grid-column: 1 / span 8;. Move it and the numbers change. Switch to Phone view to watch the media query stack everything into one column. Then read the CSS it wrote: every line is something this lesson covers.

Lab: feel what the grid properties do

Change the controls and watch the preview. The narrower widths simulate a phone. Read the generated rule at the bottom as you go — it is real CSS you can use.

Maze game

A keyboard-controlled maze with three levels and a timer.

Bridge simulator

Load a truss and watch which members go into tension.

Photo filters

Adjust brightness and contrast on an image in the browser.

Study timer

Twenty-five minutes of work, then a five minute break.

Weather log

A week of temperatures recorded and charted by hand.

Story map

Clickable locations from a book, each with a short note.

The rule this produces:

 

Check. With three fixed columns, drag the width down to 30%. The columns stay at three, the cards get very narrow, and the words start breaking one per line. Now switch to auto-fit and drag the width again: the number of columns drops to two, then one, and the text stays readable. That difference is the whole idea of responsive layout.

Repair. If your own grid overflows the screen, look for these three things in order: a fixed width in pixels on the cards, a missing minmax(0, 1fr), or a long unbroken string such as a URL. For the last one add overflow-wrap: anywhere; to the card.

Copy the generated rule into your own style.css, then give the element wrapping your project cards the matching class="cards". Save both files and refresh. If nothing changes, the class in the HTML and the selector in the CSS do not match — that is the cause nine times in ten.

Responsive design without guessing

Responsive does not mean "make a phone version". It means writing a layout that has no fixed idea of how wide it is. Two habits get you most of the way:

.page { width: 100%; max-width: 1100px; margin: 0 auto; }

@media (max-width: 700px) {
  .cards { grid-template-columns: 1fr; }
  body   { font-size: 17px; }
}

Read that query as: "when the viewport is 700px wide or less, also apply these rules." Everything outside the query still applies; the query only overrides the few properties inside it. One well-chosen breakpoint beats five guessed ones.

Test it honestly: open developer tools, use the device toolbar to check a 360px phone, then zoom the browser to 200%. A layout that survives both will survive most real visitors.

Leonardo da Vinci's Vitruvian Man illustrating the proportional geometry of the human form
Leonardo da Vinci's Vitruvian Man (Proportional Harmony, c. 1490) Based on Roman architect Vitruvius's treatise, da Vinci illustrated how human proportions relate fluidly to both the circle and the square. In modern CSS, responsive design achieves proportional harmony across any screen size by using fluid percentages, fr units, and clamp() scaling instead of rigid pixel coordinates. Credit: Leonardo da Vinci / Gallerie dell'Accademia / Wikimedia Commons · Public domain · source
Exterior glass curtain wall and structural grid of the Bauhaus building in Dessau designed by Walter Gropius
The Bauhaus Architectural Grid (Dessau, 1925) Walter Gropius and the Bauhaus movement pioneered modular grid systems, structural transparency, and unornamented functional design. CSS Grid and Flexbox bring the Bauhaus vision to the web: a mathematical layout grid that structures content cleanly, adapts to functional requirements, and unites form with purpose. Credit: Bauhaus Dessau / Wikimedia Commons · Public domain · source

Micro-interactions & visual polish

What turns a plain document into a polished digital product is responsive feedback when a visitor interacts with it:

1. Card Hover Lift

Give your project cards a subtle physical sensation when the mouse moves over them:

.card {
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.card:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 24px -6px rgba(0, 0, 0, 0.12);
}

2. Smooth Scrolling & Tactile Buttons

/* Smoothly glide to anchor links like #projects or #contact */
html {
  scroll-behavior: smooth;
}

/* Tactile click press on buttons */
button:active, .web-button:active {
  transform: scale(0.97);
}

Your starting stylesheet

This is a complete, working style.css. Replace the placeholder file from Lesson 1 with it, then customize the design tokens in :root first — those variables control the feel of the whole site.

/* ---------------------------------------------------------
   style.css — Starting stylesheet with Design Tokens & Themes
   --------------------------------------------------------- */

/* 1. Design tokens: colors, spacing, and radius */
:root {
  --space-sm: 8px;
  --space: 16px;
  --space-lg: 32px;
  --radius: 10px;

  --paper: #ffffff;
  --surface: #f8fafc;
  --ink: #0f172a;
  --ink-muted: #64748b;
  --line: #cbd5e1;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
}

/* Dark mode theme token overrides */
body.dark-theme, [data-theme="dark"] {
  --paper: #0f172a;
  --surface: #1e293b;
  --ink: #f8fafc;
  --ink-muted: #94a3b8;
  --line: #334155;
  --accent: #60a5fa;
  --accent-hover: #93c5fd;
}

/* 2. Sensible layout resets */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  padding: var(--space);
  background: var(--paper);
  color: var(--ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 18px;
  line-height: 1.6;
}

/* 3. Heading scale */
h1 { font-size: 2.2rem;  line-height: 1.2; margin: 0 0 var(--space); color: var(--ink); }
h2 { font-size: 1.6rem;  line-height: 1.25; margin: var(--space-lg) 0 var(--space); color: var(--ink); }
h3 { font-size: 1.25rem; line-height: 1.3; margin: var(--space) 0 8px; color: var(--ink); }

/* 4. Readable line measure */
p, li { max-width: 65ch; }

/* 5. Links, hover states, and focus rings */
a { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
a:hover { color: var(--accent-hover); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }

/* 6. Page container */
.page { width: 100%; max-width: 1100px; margin: 0 auto; }

/* 7. Flexbox navigation */
.site-nav {
  display: flex;
  gap: var(--space);
  align-items: center;
  flex-wrap: wrap;
  padding-bottom: var(--space);
  border-bottom: 1px solid var(--line);
}

/* 8. CSS Grid auto-fit card shelf */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr));
  gap: var(--space);
  padding: 0;
  list-style: none;
}

.card {
  padding: var(--space);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.card:hover {
  transform: translateY(-4px);
  box-shadow: 0 10px 24px -4px rgba(0, 0, 0, 0.1);
}
.card h3 { margin-top: 0; }
.card img { display: block; width: 100%; height: auto; border-radius: 6px; }

/* 9. Responsive adjustments */
@media (max-width: 700px) {
  body { font-size: 17px; padding: 12px; }
  h1 { font-size: 1.75rem; }
  .site-nav { gap: 10px; }
}

This file styles a page whose wrapper has class="page", whose nav has class="site-nav", and whose card list has class="cards" with each item class="card". Add those class names to your HTML from Lesson 2 or nothing will change.

Level-Up Challenges for CSS

Tier 1: Google Font Pairing

Visit Google Fonts, pick a distinct heading font (like Space Grotesk) and body font (like Inter), and add the <link> to your <head>.

Tier 2: Pill Badges & Tags

Style project category tags with display: inline-block; padding: 4px 10px; border-radius: 999px; font-size: 0.75rem; font-weight: 600; inside each card.

Tier 3: Dark Mode Custom Palette

Craft custom values for body.dark-theme in your CSS file and preview it in DevTools by temporarily adding class="dark-theme" to your <body>.

Before you move on

Do a last pass narrow, then wide. Nothing should scroll sideways, no text should touch an edge, and every link should outline when you press Tab. Note the one change that improved the page most.