Style sheet language · Beginner to advanced

Learn CSS step by step

Start with CSS selectors and spacing, then style readable pages and create responsive layouts with Flexbox, Grid, media queries and reusable colors. Every module explains the idea in plain language, walks through a code example and gives you a small task to try yourself.

Version snapshot: CSS Snapshot 2026. CSS has independently versioned modules rather than one single version number. This guide uses the W3C CSS Snapshot 2026 as a standards map and favors widely supported features.

Before you begin

Basic HTML helps, but each example is small enough to practise in a new HTML file.

What you’ll be able to do

Build responsive, accessible page layouts and debug style conflicts with a repeatable method.

Work through the modules in order if you’re new to CSS. If you already know the basics, use the contents list to jump to a topic. Try each example by changing one value, running it again and explaining the result in your own words.

CSS terms in simple language

Selector
A pattern that chooses which HTML elements a style rule should affect.
Cascade
The browser’s rules for choosing which matching CSS declaration takes effect.
Flexbox
A CSS layout tool for arranging items in one direction, across a row or down a column.
Grid
A CSS layout tool for arranging items across rows and columns together.
Box model
The content, inner space, border and outside space that together determine an element’s size.
Specificity
One part of the browser’s method for deciding which matching style rule should win.
Media query
A CSS condition that applies styles only when the screen or user settings match.
Pseudo-class
A selector for a state, such as a focused link or a checked checkbox.
Custom property
A reusable CSS value, often used for colors and spacing, that can change while the page runs.
In this guide · 10 modules
  1. Key terms in simple language
  2. Selectors and the cascade
  3. Box model, sizing and spacing
  4. Color, typography and readable units
  5. Normal flow, display and positioning
  6. Flexbox for one-dimensional layout
  7. Grid for two-dimensional layout
  8. Responsive design and media queries
  9. Pseudo-classes, pseudo-elements and states
  10. Custom properties, layers and maintainable CSS
  11. Transitions, transforms and animation
  12. Final project
  13. Official references
MODULE 01 / 10 · CONCEPT EXPLAINED

Selectors and the cascade

A selector tells CSS which HTML elements to style. The declarations inside the rule set things such as color, size and spacing. Sometimes several rules match the same element; the browser follows the cascade to decide which one wins. Simple selectors and clear component names make that decision easier to predict. If a style does not apply, inspect the matching rules before adding more specific selectors.

Follow this example
/* style.css */
body { color: #182538; }
.lesson-card { padding: 1.25rem; }
.lesson-card h2 { margin-block: 0 0.5rem; }
Try it yourself: Style a heading and card with classes. Inspect the computed styles and identify which rule wins.
MODULE 02 / 10 · CONCEPT EXPLAINED

Box model, sizing and spacing

CSS lays each element out as a box. The content is in the middle, padding is the space inside the edge, border is the edge itself, and margin is space outside it. With box-sizing: border-box, a card set to 400 pixels wide stays 400 pixels wide even after padding and a border are added. Logical properties such as margin-inline add space at the start and end, which also works for languages written right to left.

Follow this example
*, *::before, *::after { box-sizing: border-box; }
.card { width: min(100%, 32rem); padding: 1.5rem; border: 1px solid #d5dce5; margin-inline: auto; }
Try it yourself: Give a card a maximum width and center it; compare its width before and after border-box.
MODULE 03 / 10 · CONCEPT EXPLAINED

Color, typography and readable units

Use rem for text and spacing that should scale with the root font size, and percentages or flexible units for fluid layouts. Choose a readable line length and contrast. CSS custom properties let a design system share colors and spacing consistently.

Follow this example
:root { --ink: #182538; --accent: #c5f467; }
body { color: var(--ink); font: 1rem/1.65 system-ui, sans-serif; }
.article { max-width: 68ch; margin-inline: auto; }
Try it yourself: Set up a small theme with three custom properties and check that body text remains legible at 200% zoom.
MODULE 04 / 10 · CONCEPT EXPLAINED

Normal flow, display and positioning

Normal flow lays out block and inline content in document order. display changes how an element participates in layout. Positioning removes or offsets boxes in specific ways; sticky and fixed elements must not hide focused controls or important content.

Follow this example
.toolbar { display: flex; align-items: center; gap: 1rem; }
.notice { position: sticky; inset-block-start: 0; z-index: 2; background: white; }
Try it yourself: Make a heading-and-actions row with Flexbox; test the sticky banner at a narrow viewport.
MODULE 05 / 10 · CONCEPT EXPLAINED

Flexbox for one-dimensional layout

Flexbox is made for arranging items in one direction: across a row or down a column. Imagine placing a heading and buttons on a shelf. justify-content controls their spacing along the shelf, align-items lines them up across it, and gap adds even space between items. When the screen gets too narrow, flex-wrap lets items move onto a new line instead of being squeezed or cut off.

Follow this example
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem; }
.actions > a { padding: 0.65rem 1rem; }
Try it yourself: Create a row of action links that wraps neatly on a phone without using floats.
MODULE 06 / 10 · CONCEPT EXPLAINED

Grid for two-dimensional layout

CSS Grid arranges items in rows and columns at the same time, so it works well for a gallery or a set of course cards. repeat() describes how many columns to make, while minmax() gives each column a safe minimum and a flexible maximum. auto-fit allows the browser to fit as many columns as the available space can hold. The HTML reading order stays important even if CSS moves items around visually.

Follow this example
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 16rem), 1fr)); gap: 1rem; }
Try it yourself: Make a responsive card grid that has one column on a phone and expands naturally on wider screens.
MODULE 07 / 10 · CONCEPT EXPLAINED

Responsive design and media queries

Start with a layout that works in a narrow viewport, then add breakpoints only when the content needs them. Media queries can react to viewport width, user preferences such as reduced motion, and other environmental features. Avoid fixed page widths that cause horizontal scrolling.

Follow this example
.page { padding-inline: 1rem; }
@media (min-width: 48rem) { .page { padding-inline: 2rem; } }
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto; } }
Try it yourself: Test your layout at 320px, 768px and 1280px, and correct any overflow or unreadable line lengths.
MODULE 08 / 10 · CONCEPT EXPLAINED

Pseudo-classes, pseudo-elements and states

Pseudo-classes select an element’s state or relationship, such as :hover, :focus-visible and :checked. Pseudo-elements style a part of an element, such as ::before. Make focus indicators visible and ensure hover is never the only way to reveal key information.

Follow this example
.button:hover { filter: brightness(0.95); }
.button:focus-visible { outline: 3px solid #246b56; outline-offset: 3px; }
li + li { margin-block-start: 0.5rem; }
Try it yourself: Tab through your page and add a clear focus indicator to every interactive element.
MODULE 09 / 10 · CONCEPT EXPLAINED

Custom properties, layers and maintainable CSS

Custom properties hold reusable values and can vary in the cascade. Cascade layers let you define a predictable order for broad styles, components and overrides. Organize rules around components and remove rules that no longer describe the interface.

Follow this example
@layer reset, base, components, utilities;
@layer base { :root { --space: 1rem; } }
@layer components { .panel { padding: var(--space); border-radius: 0.75rem; } }
Try it yourself: Create a small layered stylesheet and change one custom property to restyle every panel.
MODULE 10 / 10 · CONCEPT EXPLAINED

Transitions, transforms and animation

Transitions animate a property change and transforms move or scale an element without changing surrounding layout. Use animation to communicate state, not as decoration that blocks reading. Respect prefers-reduced-motion and avoid animating expensive properties when a transform or opacity will work.

Follow this example
.card { transition: transform 160ms ease, box-shadow 160ms ease; }
.card:hover { transform: translateY(-2px); }
@media (prefers-reduced-motion: reduce) { .card { transition: none; } }
Try it yourself: Add a subtle card interaction and verify that it is disabled for a reduced-motion preference.
PUT THE MODULES TOGETHER

Your final project

Design a responsive learning dashboard using Grid, Flexbox, design tokens and reduced-motion support. Write down what the project should do, build it in small steps, and include a README that explains how to run it.

Find a guided course →

Official documentation and further reading

Use primary documentation for current language rules and version changes. The examples in this guide are learning starting points; verify details for the exact runtime and browser support your project needs.

Frequently asked questions

Does CSS have a single latest version?

No. CSS standards are developed module by module. The W3C CSS Snapshot collects the stable definition for a given year.

Should I use Grid or Flexbox?

Use Flexbox when arranging items along one axis; use Grid when rows and columns work together. They can also be combined.