North star
First project card.
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.
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>.
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.
| Selector | Matches | Use it for |
|---|---|---|
p | Every paragraph on the page | Site-wide defaults: type, color, spacing |
.card | Elements with class="card" | Anything you repeat — this is your main tool |
#contact | The one element with id="contact" | A single unique thing, usually a link target |
.card h3 | Headings inside a card | Styling parts of a component |
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.
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.
First project card.
This card also has a unique id.
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.”
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.
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.
content, padding, border, and margin) formalizes this exact physical geometry into digital browser rendering. Credit: Gutenberg Museum / Wikimedia Commons · Public domain · source
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 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!
Modern CSS supports three main ways to express colors:
HEX (#2563eb): 6 hexadecimal characters representing Red, Green, and Blue from 00 to ff. Compact and standard.RGB (rgb(37, 99, 235)): Numbers from 0 to 255. Add alpha transparency with rgba(37, 99, 235, 0.5) or rgb(37 99 235 / 50%).HSL (hsl(221, 83%, 53%)): Hue (0–360° on color wheel), Saturation (0–100%), and Lightness (0–100%). Easiest for designing complementary tint and shade scales by hand.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.
rem units, font-weight, and balanced line-height ratios for optimal reading rhythm. Credit: William Caslon / Wikimedia Commons · Public domain · source 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.
color value in the Styles panel and click its color swatch.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; }
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.
| Property | Common values | Visual effect |
|---|---|---|
justify-content (Main Axis) | flex-start | center | space-between | Pushes items to the left, groups them in the center, or spreads them evenly from edge to edge. |
align-items (Cross Axis) | center | stretch | flex-start | Centers items vertically, stretches them to matching heights, or aligns tops. |
gap | 16px | var(--space) | Gives items breathing room without messy margin calculations. |
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.
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.
A keyboard-controlled maze with three levels and a timer.
Load a truss and watch which members go into tension.
Adjust brightness and contrast on an image in the browser.
Twenty-five minutes of work, then a five minute break.
A week of temperatures recorded and charted by hand.
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 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:
width: 100%, max-width: 1100px and 1fr adapt on their own. width: 960px cannot..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.
fr units, and clamp() scaling instead of rigid pixel coordinates. Credit: Leonardo da Vinci / Gallerie dell'Accademia / Wikimedia Commons · Public domain · source
What turns a plain document into a polished digital product is responsive feedback when a visitor interacts with it:
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);
} /* 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);
} 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.
Visit Google Fonts, pick a distinct heading font (like Space Grotesk) and body font (like Inter), and add the <link> to your <head>.
Style project category tags with display: inline-block; padding: 4px 10px; border-radius: 999px; font-size: 0.75rem; font-weight: 600; inside each card.
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>.
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.