🎨

CSS Fundamentals

Level
8 lessons31 exercises~6h

Learn CSS from scratch with 31 hands-on exercises and a live preview editor. Selectors, colors and units, the box model, typography, display and positioning, flexbox, backgrounds and borders, transitions, all runnable in your browser with instant visual feedback.

01. Selectors & Syntax

How a CSS rule is built and how to target elements.

The anatomy of a CSS rule

Every CSS rule has a selector and a declaration block. Inside the block you write property: value; pairs.

selector {
  property: value;
}

The core selectors

  • Type: p targets every paragraph.
  • Class: .badge targets elements with class="badge". Reusable.
  • ID: #title targets the single element with id="title". Unique.
  • Grouping: h1, h2 applies the same rule to several selectors.
  • Descendant: nav a targets links inside a nav.

Specificity in one line

When rules conflict, an ID beats a class, and a class beats a type selector. Keep selectors as simple as the job allows.

Exercises (4)

Type selector

Select every <p> element and set its color to red.

CSS
Previewlive

Free forever, no ads, no tracking. Support the project