Skip to content
Learn Netverks

Lesson

Step 15/31 48% through track

css-variables-theme

CSS variables and simple theming

Last reviewed May 28, 2026 Content v20260528
Track mode
iframe_html
Means
HTML preview sandbox
Reading
~1 min
Level
intermediate

This lesson

This lesson teaches CSS variables and simple theming—the ideas, syntax, and habits you need before moving on in HTML & CSS.

Reusable tokens and variables keep large stylebases consistent and cheaper to retheme.

You will apply CSS variables and simple theming in contexts like: Landing pages, dashboards, marketing sites, and portfolio pieces built without a framework.

Read the lesson, edit HTML/CSS in the playground, press Run to preview, then answer the lesson MCQs.

When the previous lesson's MCQs feel easy and you can explain CSS variables and simple theming in your own words.

Custom properties (--name) let you define colors, spacing, and fonts once in :root, then reuse them across components. Changing theme becomes a one-line update.

Define and consume

:root {
  --brand: #4f46e5;
  --surface: #ffffff;
}
.card { background: var(--surface); border-color: var(--brand); }

Scoped variables

You can set variables on a component (e.g. .card { --card-pad: 1rem; }) so variants do not pollute the global theme.

Practice

  1. Toggle data-theme="dark" on <html> in the playground (uncomment the attribute).
  2. Add a new token --radius and use it on buttons and cards.

Important interview questions and answers

  1. Q: CSS variables vs Sass variables?
    A: CSS variables are live in the browser and can change at runtime; Sass compiles away at build time.
  2. Q: Where are custom properties inherited?
    A: They inherit like other properties—define on `:root` for global defaults.
  3. Q: Fallback in `var()`?
    A: `var(--brand, #000)` supplies a backup if undefined.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs in your browser in a sandboxed frame. Backend runners appear when this track’s profile allows them.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • What part of this lesson needs a second read?
  • What would you try differently in a real project?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump