×

css · level 3 · unit 1 · lesson 1

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

Name a value once with a , then reuse it.

Real sites repeat the same brand colour in dozens of rules. Change it, and you hunt through every one. A custom property fixes that: a value you name yourself, starting with two dashes, like --brand: #0f766e;.

Set it on , a selector for the top element of the page, and every element can use it. To read it back, use : write var(--brand) wherever the value should go.

Teams call these shared, named values tokens. Change a in one place and every rule that reads it follows.

<h1>Fern and Co</h1>
<p>Plants delivered to your door.</p>
<a class="btn" href="https://example.com/shop">Shop now</a>
:root {
  --brand: #0f766e;
}
h1 {
  color: var(--brand);
}
.btn {
  padding: 8px 16px;
  color: white;
  background-color: var(--brand);
}

Press show my page to see it here.

Change #0f766e to #9a3412 and run it again: the heading and the button change together.