What you'll learn
- Adjust a component's CSS to match a spec
- Read HTML structure and CSS rules, including selectors and declarations
- Explain the box model and how the cascade decides which rule wins
- Use browser DevTools to inspect real values and propose precise fixes
Read the HTML structure and CSS rules behind a component and adjust spacing, type, contrast and layout to match a spec.
Why it matters
You do not need to be a developer to design for the web, but being able to read HTML and CSS changes how you work. You can inspect a live page to see why it does not match the design, suggest a precise fix ("paddingSpace inside an element's border, which takes the element's background colour. is 10px, the spec says 24px"), understand what is cheap or expensive to build, and make small fixes yourself in a pull request if your team allows it. Many product designer job listings ask for "a working knowledge of HTML and CSS" for exactly these reasons.
The core idea: structure, then style
HTML describes structure and meaning: this is a heading, this is a button, this is a list. CSS describes presentation: colour, size, spacing, layout.
<div class="plan-card">
<h2 class="plan-card__title">Team plan</h2>
<button class="btn btn--primary" type="button">Choose plan</button>
</div>- Elements (
div,h2,button) are the building blocks. The element choice matters for accessibility: a real<button>is focusable and works with the keyboard; a<div>styled like a button is not. classattributes are labels CSS uses to find elements. Names likeplan-card__titlefollow a common convention (BEMA class-naming convention (block, element, modifier), such as plan-card__title, that often mirrors component names.: block, element, modifier), which often mirrors design-system component names.
A CSS rule is a selectorThe part of a CSS rule that says which elements the rule applies to, such as .plan-card. plus declarations:
.plan-card { /* selector: elements with class plan-card */
padding: 24px; /* property: value; */
border-radius: 12px;
}Properties designers adjust most
| Design idea | CSS property | Example |
|---|---|---|
| Inner spacing | padding | padding: 8px 16px; (top/bottom 8, left/right 16) |
| Outer spacing | margin | margin: 0 0 16px; |
| Corner radius | border-radius | border-radius: 12px; |
| Text size and weight | font-size, font-weight, line-height | font-weight: 600; |
| Colour | color (text), background | color: #374151; |
| Minimum size | min-height, min-width | min-height: 44px; |
| Side-by-side layout | display: flex and gap | display: flex; gap: 8px; |
Two concepts explain most surprises:
- The box modelThe idea that every element is a box of content, then padding, then border, then margin.. Every element is a box: content, then padding, then border, then marginSpace outside an element's border that separates it from neighbouring elements.. Padding is inside the border (it gets the background colour); margin is outside.
- The cascadeThe CSS process that picks a winner when several rules target one element: the more specific selector wins, then the later rule.. When several rules target the same element, the more specific selector wins, and among equals the later rule wins. If your change "does nothing", another rule is probably overriding it.
Inspecting a live page
Every desktop browser has free developer tools. In Chrome, Edge or Firefox, right-click an element and choose Inspect.
- The Elements (or Inspector) panel shows the HTML; hover to highlight boxes on the page.
- The Styles panel shows the CSS rules that apply, with overridden values crossed out.
- The Computed panel shows final values and a box-model diagram with padding and margin.
- You can edit values live to try a fix. Nothing is saved; reloading resets it.
That is how you turn "the card looks cramped" into "the card's padding is 10px; the spec is 24px (space-4)".
Worked example: matching a spec
A plan card was built from a spec but looks wrong. Inspecting it shows:
.plan-card { padding: 10px; border-radius: 3px; } /* spec: 24px, 12px */
.plan-card__title { font-weight: 400; } /* spec: 600 */
.plan-card__badge { color: #a3a3a3; background: #fff; } /* about 2.5:1, fails 4.5:1 */
.btn { padding: 4px 12px; } /* about 27px tall; spec 44px */
.plan-card__actions { } /* buttons should sit in a row, 8px gap */Fixes:
.plan-card { padding: 24px; border-radius: 12px; }
.plan-card__title { font-weight: 600; }
.plan-card__badge { color: #374151; } /* about 10:1 on white */
.btn { min-height: 44px; padding: 8px 16px; }
.plan-card__actions { display: flex; gap: 8px; }In a real codebase these values would be tokens (var(--space-4)), as in the tokens lesson.
Common mistakes
- Fixing with a
<div>. If something acts like a button, it should be a<button>; a link that goes somewhere should be an<a href>. - Using margin for inner spacing (or the reverse). Inside the border is padding.
- Fixed heights on text containers. Text grows when users zoom or translate; prefer
min-heightand padding. - Pixel-pushing in DevTools and forgetting to write it down. Changes vanish on reload; record the fix in the ticket.
- Changing shared CSS that other components use without checking with the team.
Quick recap
- HTML gives structure and meaning; CSS gives presentation.
- A CSS rule is a selector plus property-value declarations; the cascade decides which rule wins.
- Know the box model: content, padding, border, margin.
- Use browser DevTools (Inspect) to find the real values and propose precise fixes.
Try it
On the Do tab you will adjust a plan card's CSS so it matches its spec: padding, radius, weight, contrast, button height and layout.
Key terms (6)
- selector
- The part of a CSS rule that says which elements the rule applies to, such as .plan-card.
- box model
- The idea that every element is a box of content, then padding, then border, then margin.
- cascade
- The CSS process that picks a winner when several rules target one element: the more specific selector wins, then the later rule.
- padding
- Space inside an element's border, which takes the element's background colour.
- margin
- Space outside an element's border that separates it from neighbouring elements.
- BEM
- A class-naming convention (block, element, modifier), such as plan-card__title, that often mirrors component names.