CSS Tutorial
Free CSS tutorial for beginners. Learn CSS step by step with examples you can edit and run: selectors, box model, Flexbox, Grid and responsive design.
103 lessons, free
This tutorial teaches CSS from a single declaration to a responsive layout you could ship: the cascade, the box model, Flexbox and Grid, and the modern features that replaced a decade of workarounds. Every example runs in the editor on the page.
What is CSS?
CSS is a list of rules. Each one says which elements to affect and what to change about them. That is the whole model, everything else is detail about which rule wins.
It is not a programming language. There are no loops and no conditions in the usual sense, which is why it feels strange coming from JavaScript, and why the hard part is never syntax.
A rule, and what each part is called
css
/* selector { property: value } */
.card {
padding: 1rem;
border-radius: 12px;
background: #ffffff;
}
/* A class applies to every element carrying it. */
.card:hover {
border-color: #cc4600;
}Why it feels unpredictable at first
Two rules can both apply to the same element, and CSS has to pick one. That decision is the cascade, and almost every "why isn't this working" moment traces back to it.
Three things decide the winner, in order: importance, then specificity, then which rule came last. An id beats a class, a class beats a tag, and inline styles beat all of them.
Once you can read a rule and say why it lost, CSS stops being guesswork. That is the single most valuable thing in this tutorial, and it is covered early.
What this tutorial covers
- Foundations
Selectors, the cascade, specificity, inheritance, custom properties.
- The box model
Margin, border, padding, sizing, and why
box-sizingchanges everything.- Typography and colour
Fonts, spacing, colour formats and contrast.
- Layout
Flexbox for one direction, Grid for two, and how to tell which a design needs.
- Responsive design
Media queries, container queries, fluid type and modern units.
- Modern CSS
Nesting, cascade layers,
:has(), clamp, logical properties, animations.
103 lessons, grouped so you can see how much is left at each stage rather than facing one long list.
Layout is the part worth slowing down for
Flexbox arranges things along one axis; Grid arranges them along two. Choosing wrongly is what makes a layout fight back, and the two chapters on it are the ones most worth doing slowly.
The auto-fit line in this example is a responsive card grid with no media query at all. That is roughly the amount of CSS the same layout used to take in 2015.
Two lines that replace a page of floats
css
.row {
display: flex;
gap: 1rem;
}
.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
gap: 1rem;
}What you need before you start
Basic HTML: elements, attributes, classes and how a document nests. If that is shaky, work through the HTML tutorial first: CSS styles HTML, so there is nothing to style until you can write it.
No JavaScript is needed. A browser and a text editor are enough, and every example here runs in the Try It editor without installing anything.
How long this takes
Selectors, colours and the box model take a few evenings, and they are enough to restyle a page you already have.
Layout takes longer. Not because Flexbox and Grid are complicated, but because you have to build a few things before the choice between them becomes obvious rather than a coin flip.
Responsive design is quicker than people expect once layout has clicked, because modern CSS does most of the work you used to write by hand.
CSS properties you will use most
Select a property to see its lesson.
colorText colorbackground-colorBackground colorfont-familyTypefacefont-sizeText sizemarginSpace outside an elementpaddingSpace inside an elementborderLine around an elementwidth, heightSizedisplayHow an element takes part in layoutpositionWhere an element is placedjustify-contentAlignment along a Flexbox rowgrid-template-columnsColumns in a grid
CSS lessons in order
1CSS Introduction
2CSS Foundations
3CSS Selectors
4CSS Colors and Backgrounds
5CSS Text & Fonts
6CSS Box Model
7CSS Layout
8CSS Flexbox
9CSS Grid
10CSS Lists, Tables & Forms
11CSS Effects
12CSS Animations & Transitions
13CSS Responsive Design
14Modern CSS Authoring
15CSS Accessibility
16CSS Output & Performance
17CSS Projects
Look up when you need it
Common questions
CSS. It is the other half of every page you will build, and it is far more forgiving: a mistake makes something look wrong rather than stopping the page from working.
Yes. They solve different problems and are used together constantly: Grid for the page skeleton, Flexbox for the row of buttons inside one of its cells. Neither replaces the other.
You can, and plenty of good work does. But every one of those tools is CSS underneath, and the moment something does not look right you are debugging CSS. Learning the framework first means you cannot.
Nine times out of ten it is specificity, another rule is winning, or the selector does not match what you think it does. The chapter on the cascade shows how to check both in the browser in about ten seconds.
No. There are hundreds and nobody knows them all. Learn the twenty you use daily, understand the cascade, and look up the rest: that is what every working developer actually does.
