Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 3.4 — Colours
CSS · Example 1 of 3

Seven spellings, one colour

The browser stores every sRGB colour as red, green and blue numbers, whatever spelling you used.

CSS can write the same colour many ways (names, hex, rgb(), hsl()), add transparency with an alpha value, follow the text colour with currentColor, and erase colour with transparent; the browser turns them all into the same red, green and blue numbers.

Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.

Ready for more? This phase has 5 hands-on exercises with automatic checks.

Practice questions

Write the code in the editor, run it, then open the model answer to compare.

01

Write the colour rgb(255 165 0) (orange) as hex, and give a version with 25% alpha in both hex and rgb() form.

02

Make a .badge with text colour #be123c, a 2px border in the same colour, and a background of the same red at 10% alpha.

Explain it without notes

01

List four ways to write the same opaque colour and say how the browser stores it.

02

How do hsl()'s three numbers work, and why is it handy for making shades?

03

What is the difference between opacity: 0.5 and a colour with 50% alpha?

04

What is currentColor and where is it useful?

Seven spellings, one colour

Preview

Press Run to see the page.

Console

Nothing logged yet.

Expected console output

rebeccapurple -> rgb(102, 51, 153)
#663399 -> rgb(102, 51, 153)
#639 -> rgb(102, 51, 153)
rgb(102 51 153) -> rgb(102, 51, 153)
rgb(102, 51, 153) -> rgb(102, 51, 153)
hsl(270 50% 40%) -> rgb(102, 51, 153)
hsl(270deg, 50%, 40%) -> rgb(102, 51, 153)