HTML and CSS lesson 12: Color on the web: names, hex and rgb
US version. US grades and US spelling. · UK version of this lesson
Screens mix red, green and blue light. CSS colors can be names (red), hex codes (#ff0000) or rgb(255, 0, 0); background-color sets the color behind. A complete 40-minute HTML and CSS lesson for beginners (Grades 6–7), from Unit 4: CSS: style rules. You build real web pages right here in your browser – nothing to install.
- Time
- 40 minutes + 20 min homework
- Grade
- Grades 6–7 (ages 11–12)
- You need
- A computer or tablet, paper and a pencil
- Graded
- Instantly, with explanations
For parents: how to use this lesson
You don't need to know HTML yourself. The lesson explains each step on screen, the way Mr Babbage, our Head of Computing, likes it: a worked example first, then a go for your child. When your child builds a page, the browser draws it straight away and Classfern grades it with a checklist.
- Read what your child will learn together.
- Press Start the lesson below. Sit with your child for the teaching and the worked example (about 15 minutes): ask them to point at each tag and say what it does.
- Let them do the practice on their own. If a page doesn't look right, the checklist says what is missing – let them find the mistake before you help.
- Finish with the exit questions and the talk question: “Why do you think hex codes use base 16?”
- Later that day or the next day: the homework (20 minutes), then a practice test.
Watch out for
#ff0000is blue. The first pair is red: #RRGGBB.background-colourworks. CSS spells itbackground-color.
Miss Lovelace's tip for home: ask your child to change one thing on their page – a word, a color, a size – and predict what will happen before they look. Predicting first is how programmers learn fastest.
What your child will learn
Learning goal: use color names, hex codes and rgb().
Success looks like
- I can use color names, hex codes and
rgb(). - I can read a hex code as red, green and blue.
- I can set text and background colors.
Key words
RGB · hex code · hexadecimal · color name · background-color · pixel
What to have ready
- A device with a web browser (pages are built and checked right in the browser – nothing to install)
- Paper for planning and sketching
- A keyboard helps for typing code (a tablet works too)
The big ideas (for the adult)
Every pixel on a screen mixes red, green and blue light. rgb(255, 0, 0) means "all the red, no green, no blue" – so, red. rgb(0, 0, 0) is no light (black) and rgb(255, 255, 255) is all the light (white).
A hex code is the same three numbers written in base 16: #RRGGBB, where each pair goes from 00 (none) to ff (255). #ff0000 is red and #000080 is navy. A 3-digit code doubles each digit: #f00 = #ff0000. This is a real example of numbers representing pictures in a computer.
color sets the text color and background-color the color behind it – both with the American spelling. CSS knows 148 color names; a misspelt name (like redd or lightred) is simply ignored. Interestingly, both grey and gray work.
Worked example: three ways to say a color
CSS:
h1 { color: #1e90ff; }
h2 { color: tomato; }
p { color: rgb(46, 139, 87); background-color: #fffaf0; }HTML:
<h1>Hex</h1> <h2>Name</h2> <p>rgb()</p>
The lesson, step by step
| Part | Time | How it is checked |
|---|---|---|
| Starter | 5 min | Graded by Classfern |
| Learn | 8 min | Read, watch and talk |
| See it | 7 min | Graded by Classfern |
| Practice | 15 min | Graded by Classfern |
| Check and reflect | 5 min | Graded by Classfern + self-check |
The lesson
It runs here on the page. No sign-up and no names – nothing you type is sent anywhere. Each visit picks a new mix of questions.
Homework
20 minutes: predict what the browser will do, build or fix a short page, and check the key ideas – then a short reflection. New questions every time, all graded instantly.
Practice tests
- CSS rules, selectors and color test12 questions · graded instantly
- Mixed HTML and CSS test20 questions · graded instantly
- Mixed HTML and CSS test20 questions · graded instantly
All computer science practice tests · All 20 HTML and CSS lessons
Curriculum
CSTA K–12 Computer Science Standards (2017), grades 6–8: 2-DA-07 – Represent data using several encoding schemes.
The standard codes are CSTA's; the descriptions are our own words.
Our lessons and questions are our own. They are not written or endorsed by any government department, testing agency or exam board. HTML and CSS are open web standards; Classfern is not affiliated with the organisations that publish them.