Skip to content
Guest
Learn CSS · Course Syllabus Show lessons
Core Foundations · 9 min read · Beginner

Modern Colors, Units & Custom Properties

Build flexible design systems using CSS custom properties (--vars), rem/ch/dvh units, color-mix(), and light-dark().

What you'll learn

  • Define and reuse theme tokens with CSS Custom Properties (--accent)
  • Choose accessible relative units (rem, ch, %) over rigid pixels
  • Mix and adapt colors dynamically with color-mix() and light-dark()

Modern CSS gives you built-in design-token variables and dynamic color functions, no preprocessor required.

CSS Custom Properties (--vars)

Declare variables on :root and read them anywhere with var(--name, fallback):

:root {
  --brand: #2563eb;
  --radius: 0.75rem;
}
.button {
  background: var(--brand);
  border-radius: var(--radius);
}

Choosing the Right CSS Units

UnitRelative ToBest Used For
remRoot <html> font size (usually 16px)Font sizes, spacing (respects user zoom settings!)
chWidth of the "0" characterComfortable paragraph line lengths (max-width: 65ch)
dvhDynamic mobile viewport heightFull-screen heroes without mobile address-bar cutoff
%Parent container dimensionFluid widths

Fill-in-the-Blank Exercise

CSS Custom Properties

Define a custom property named --accent on :root and apply it to the button background.

:root {
: #2563eb;
}
.btn {
background: (--accent);
}

Try It Yourself

Change --brand in :root from #2563eb to #7c3aed or #059669 and watch the entire card theme update automatically!

One-Token Theme with color-mix()
Live Result

Check Your Understanding

Score: 0 / 1

1. Why is rem preferred over px for font sizes?

Study Workspace

Finished this lesson?

Your progress is saved locally in your browser, no account needed.

Search courses, lessons, and references

Type to search across all courses, lessons, and quick references.

Press Esc to close Powered by Pagefind