learn.web Back to the curriculum ↗

First steps on the web / 04

CSS: the skin

Control layout, color, and typography with the cascade, the box model, and flexbox.

Time
80 min
Mode
Learn → Make → Check
Path
Web Foundations

By the end, you can…

CSS is the presentation layer

CSS turns the skeleton into a designed page. Every element is a box with content, padding, border, and margin—the box model. Spacing, alignment, and rhythm come from controlling these boxes, not from guessing pixels.

The cascade resolves conflicting rules: later rules and more specific selectors win. A simple way to keep it calm: style elements directly, use classes for repeated components, and keep one source of truth in your own stylesheet.

Give your profile a calm, readable design

Start with a type scale: one size for headings, one for body text, comfortable line height. Choose two or three colors and use them deliberately. Add padding and margin consistently so spacing feels intentional.

Use flexbox to lay out navigation and simple rows. Add one media query so the layout still works on a narrow phone. Check it at 200% zoom—text should reflow, not break.

Working example
.profile-card {
  display: flex;
  gap: 1rem;
  padding: 1.25rem;
  border: 1px solid #ddd;
  border-radius: .75rem;
}
@media (max-width: 40rem) {
  .profile-card { flex-direction: column; }
}

Your studio task

Make — Style your profile page into a calm, readable layout.

  1. Establish a type scale and a two- or three-color palette.
  2. Add padding, margin, and borders until spacing feels deliberate.
  3. Lay out one section with flexbox.
  4. Add one media query and test at 200% zoom.
Definition of done

It uses the box model deliberately, one flex or grid layout, a visible spacing rhythm, and a responsive rule.

Open the interactive lesson with its workspace ↗

Knowledge check

Which parts make up the box model?
  1. Content, padding, border, and margin
  2. Header, body, and footer
  3. HTML, CSS, and JavaScript
Reveal answer (A)

Every element renders as content surrounded by padding, border, and margin.

Two rules target the same element; which one wins?
  1. The first rule in the file
  2. The more specific selector
  3. The shortest selector
Reveal answer (B)

More specific selectors win in the cascade, then source order decides ties.