Explain it simply
Explain it simply
You have now covered the core of CSS: choosing elements with selectors, adjusting colour, fonts, text and backgrounds, controlling spacing with the box model, building layouts with Flexbox and Grid, and writing media queries for responsive design, from the basics up to practical use.
Knowing CSS is not about memorising properties. It is about looking at a website and thinking "how would I break this into boxes and build it?" Once you reach that stage, your CSS brain quietly gets to work every time you look at a page. This lesson packs that way of thinking into four questions.
Problem → Why → Solution
The problem: knowing properties, not why they fail
A learner wants the hero text in the exact middle of the screen. They remember "to centre, use flex with align-items: center" and add height: 100% for good measure. The text stays glued to the top of the page. Next they try margin-top: 300px, which looks centred on their laptop and pushes the text off the bottom of a phone screen.
The same thing happens to people who know framework utility class names but not the CSS behaviour underneath. When a class does not work, they have no idea what to try next.
.hero {
display: flex;
align-items: center; /* centre... in what height? */
justify-content: center;
height: 100%; /* 100% of the body's auto height */
}The layout context is missing
align-items: center centres items within the container's spare space. height: 100% only works when the parent has a definite height, and the body's height is auto, so .hero is only as tall as its content and there is no spare space to centre in. Giving it the screen height directly, with min-height: 100vh, fixes it. The skill is asking "in which context?" rather than "which property?".
Core concept: four questions every element answers
When the browser draws an element, it answers these four questions in order. Every chapter of this course answered one of them, and when you meet a bug, the job is to find which question got the wrong answer.
The CSS pipeline
----------------
HTML element
|
v
[1] Cascade -----> computed values (color, width, ...)
|
v
[2] Box model ---> content + padding + border + margin
|
v
[3] Layout ------> flow | flex | grid | position
|
v
[4] Adapt -------> fluid units, media / container queries1. Where do the values come from? (cascade)
Selectors match the element, and among competing rules the winner is chosen by origin, specificity and then source order. Properties such as color and font inherit from the parent, and so do custom properties.
2. How big is the box? (box model)
Content, padding, border and margin make the box. box-sizing: border-box counts padding and border inside the width. With no width, a block fills its parent, and its height follows the content.
3. Which layout places it?
Normal flow is the default. Use flexbox to arrange items along one axis, a row or a column, and grid when you control rows and columns together. position: absolute or fixed takes an element out of the flow and places it against its containing block.
4. How does it adapt?
Fluid values such as min(), clamp(), % and rem work on every screen, and media or container queries are added only where the content breaks. User preferences such as hover capability, dark mode and reduced motion are respected at this stage too.
| You want to... | Reach for |
|---|---|
| Line nav links up in a row | Flexbox + gap |
| Build a sidebar + main shell | Grid (grid-template-columns) |
| Pin a badge on a card | position: relative + absolute |
| Share theme colours | Custom properties |
- Cascade: which value wins?
- Box: how big is it?
- Layout: what places it?
- Adapt: how does it change?
When something breaks, walk the pipeline from the top. The first question with a wrong answer is the place to fix.
General pattern
:root { --token: value; } /* 1. shared values */
*, *::before, *::after { box-sizing: border-box; } /* 2. predictable boxes */
.shell { display: grid; gap: var(--token); } /* 3. two-dimensional layout */
.row { display: flex; gap: var(--token); } /* 3. one-dimensional layout */
@media (min-width: BREAKPOINT) { /* 4. adapt where content breaks */
.shell { grid-template-columns: MAIN SIDE; }
}The skeleton of most stylesheets: tokens, a box-sizing reset, grid for the page shell, flex inside components, and a breakpoint where the content breaks.
The whole course in one page
This short page uses one idea from every chapter: custom properties, box-sizing, a flex header, a grid shell, a fluid width, a hover transition and a mobile-first media query. Run it and, for each line, work out which pipeline question it answers.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>CSS in one page</title>
<style>
:root { --accent: #2563eb; --space: 16px; --radius: 12px; }
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, sans-serif; line-height: 1.6; }
.site-header {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
align-items: center;
gap: var(--space);
padding: var(--space);
background: #0f172a;
color: #fff;
}
.site-header nav { display: flex; gap: var(--space); }
.site-header a { color: inherit; }
.page {
display: grid;
gap: var(--space);
width: min(100% - 2 * var(--space), 1100px);
margin: var(--space) auto;
}
.card {
padding: var(--space);
border: 1px solid #cbd5e1;
border-radius: var(--radius);
transition: border-color 0.2s;
}
.card:hover { border-color: var(--accent); }
@media (min-width: 768px) {
.page { grid-template-columns: 2fr 1fr; }
}
</style>
</head>
<body>
<header class="site-header">
<strong>CSS Notes</strong>
<nav><a href="#">Guides</a><a href="#">Projects</a></nav>
</header>
<main class="page">
<article class="card">Main content: normal flow inside a grid cell.</article>
<aside class="card">Sidebar: stacks below the article on phones.</aside>
</main>
</body>
</html>Code breakdown
- Tokens (cascade)
:root { --accent: #2563eb; --space: 16px; --radius: 12px; }Custom properties inherit from :root to every element, so spacing and colour are controlled in one place.
- One-dimensional layout
justify-content: space-between;The header is a single row: the logo is pushed left and the nav right, and flex-wrap lets the nav drop to a new line when space runs out.
- Fluid shell
width: min(100% - 2 * var(--space), 1100px);min() happily mixes var() into its math: a 16px gutter on each side, capped at 1100px.
- Two-dimensional layout
.page { grid-template-columns: 2fr 1fr; }It lives inside the media query, so only from 768px is the space split 2:1. Below that the grid keeps its default single column and the cards stack.
- State + motion
.card:hover { border-color: var(--accent); }The pseudo-class plus the transition changes the border colour smoothly over 0.2s.
A dark navy header at the top ("CSS Notes" on the left, two links on the right). Up to 767px the article and aside cards are stacked; from 768px they sit side by side at 2fr and 1fr. Hovering a card turns its border blue.What to learn next
- Study semantic HTML more deeply (header, main, nav, article, form labels)
- Build five practice layouts with Flexbox and Grid (navbar, hero, pricing, dashboard, gallery)
- Build one mobile-first landing page from start to finish
- Make a small design system with CSS variables for colour, spacing and radius
- After that, add interaction with JavaScript
When you use newer features such as container queries, :has() or subgrid, practise progressive enhancement: write a base layout that works in every browser first, then improve it with @supports where the feature exists. Check browser support in MDN's compatibility tables or on caniuse.com.
.gallery { display: flex; flex-wrap: wrap; gap: 16px; } /* works everywhere */
@supports (display: grid) {
.gallery {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
}
}In real projects
In real projects
Interviews and code reviews ask "how would you approach this layout?" and "why won't this element move?" far more often than "what is this property's syntax?". You can find syntax on MDN in seconds; taking a problem apart through the pipeline comes only from practice.
Teams that use frameworks such as Tailwind or Bootstrap rely on the same foundation: flex, grid-cols-3 and the md: prefix are this course's properties and media queries under another name, so your CSS understanding survives any framework change. The best practice is mini projects. Build a profile card, a pricing section, a navbar, a hero section and a dashboard card grid one at a time, and your CSS muscle memory will grow.
Common mistakes
Mistakes people make at the end of a course
Using one layout tool for everything
Fans of grid lay out the icon and label inside a button with grid; fans of flex build the page shell from flex-basis percentages. Both work, but the code gets tangled. Ask "one axis or two?" before choosing.
Adding properties without checking the context
Like height: 100% in the problem section, top and left do nothing without a position, z-index needs a positioned element, and justify-self is ignored on flex items. When a property has no effect, check on MDN which context it needs instead of piling on more properties.
Watching tutorials instead of building
Watching one video or article after another feels like understanding, until you open an empty file and do not know where to start. Rebuild one section of a simple real website, then compare your solution with the original in DevTools.
Mini challenge
A pricing section with the full toolkit
Build a pricing section with three plans. It stacks on phones and becomes three columns from 800px. Mark the middle plan as featured by overriding a single custom property, which recolours it.
- .plan uses --plan-accent for its border and its button background
- .plan--featured overrides only --plan-accent
- The price gets a fluid font size with clamp()
- Mobile-first: one column at the base, three at @media (min-width: 800px)
- Buttons have a :focus-visible outline
/* Markup: section.pricing > article.plan*3 (middle one also .plan--featured),
each with h3, p.price and a.plan__cta */
.pricing {
/* TODO: mobile-first grid, gap, fluid width, centred */
}
.plan {
--plan-accent: #64748b;
/* TODO: padding, radius, border in the accent colour */
}
.plan--featured {
/* TODO: override one custom property only */
}
.price {
/* TODO: clamp() font size */
}
/* TODO: .plan__cta uses the accent; add a :focus-visible outline */
/* TODO: three columns from 800px */Expected: At 375px the three plans are stacked; at 1024px they share one row. The featured plan's border and button are blue, the other two are grey, and the price text grows with the screen.
Show hint
Custom properties inherit, so changing --plan-accent on .plan--featured recolours both the border and the button inside that card, with no extra rules.
Show solution
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, sans-serif; }
.pricing {
display: grid;
gap: 16px;
width: min(100% - 32px, 1000px);
margin: 32px auto;
}
.plan {
--plan-accent: #64748b;
padding: 20px;
border: 2px solid var(--plan-accent);
border-radius: 12px;
}
.plan--featured { --plan-accent: #2563eb; }
.price { margin: 8px 0 16px; font-size: clamp(1.75rem, 1.25rem + 2vw, 2.5rem); }
.plan__cta {
display: inline-block;
padding: 10px 16px;
border-radius: 8px;
background: var(--plan-accent);
color: #fff;
text-decoration: none;
}
.plan__cta:focus-visible {
outline: 3px solid var(--plan-accent);
outline-offset: 3px;
}
@media (min-width: 800px) {
.pricing { grid-template-columns: repeat(3, 1fr); }
}
</style>
</head>
<body>
<section class="pricing">
<article class="plan"><h3>Free</h3><p class="price">$0</p>
<a class="plan__cta" href="#">Start</a></article>
<article class="plan plan--featured"><h3>Pro</h3><p class="price">$12</p>
<a class="plan__cta" href="#">Upgrade</a></article>
<article class="plan"><h3>Team</h3><p class="price">$40</p>
<a class="plan__cta" href="#">Contact</a></article>
</section>
</body>
</html>Quick quiz 1 / 3
Quick quiz 2 / 3
Quick quiz 3 / 3
What to remember
- Every element passes through the pipeline: cascade, box model, layout, adapt
- Choose flexbox for one axis and grid for rows and columns together
- When a property has no effect, check the context it needs (definite height, position) first
- Add newer features as progressive enhancement with @supports
- Building mini projects one at a time is the best way to make CSS stick
CSS Snapshot 2025 — W3C