Skip to main content

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-sizing changes 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 lessons in order

  1. 1CSS Introduction

  2. 2CSS Foundations

  3. 3CSS Selectors

  4. 4CSS Colors and Backgrounds

  5. 5CSS Text & Fonts

  6. 6CSS Box Model

  7. 7CSS Layout

  8. 8CSS Flexbox

  9. 9CSS Grid

  10. 10CSS Lists, Tables & Forms

  11. 11CSS Effects

  12. 12CSS Animations & Transitions

  13. 13CSS Responsive Design

  14. 14Modern CSS Authoring

  15. 15CSS Accessibility

  16. 16CSS Output & Performance

  17. 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.