Lesson 3 ยท Make a web page
Paint with CSS
Mix colors and change sizes to make your page look the way you want.
About 15 minutes
Tab indents. Press Escape, then Tab, to leave the editor.
Your HTML page has all the right parts, but it's a bit plain, like a house with no paint. ๐ In this lesson you'll use CSS to add colors and change sizes, so your page looks just the way you want.
CSS is paint and clothes
Remember the three helpers? HTML is the bones. CSS is the paint and the clothes. It doesn't change what is on the page. It changes how everything looks. ๐
CSS is short for Cascading Style Sheets. "Style" means how something looks. You don't need to remember the long name. Everyone just says "CSS".
A CSS rule
You talk to the browser in CSS by writing rules. Here's one:
h1 {
color: blue;
}
This rule has three parts:
h1is the selector. It selects, or picks, which parts of the page to paint. This one picks every<h1>.coloris the property. It's the thing you want to change.blueis the value. It's what you want to change it to.
Notice the punctuation. The curly brackets { } hold everything for that selector. A colon : goes after the property, and a semicolon ; goes at the end, like a full stop at the end of a sentence.
Colors made of light
You can use color names in CSS, like tomato, gold, skyblue or hotpink. There are well over a hundred of them!
But how does a screen actually make a color? Look really closely at a screen with a magnifying glass and you might see tiny dots of red, green and blue light. ๐ด๐ข๐ต By mixing those three lights, a screen can show almost any color.
In CSS you can choose exactly how much of each light to use, from 0 (off) to 255 (as bright as it goes). That's written like this: rgb(255, 0, 0). The three numbers are red, green and blue. That one is bright red.
Mixing light isn't like mixing paint. Try it below and see what surprises you!
Lab
Color mixer
Screens make every color from red, green and blue light. Slide them to mix your own.
Try a named color
color: rgb(255, 99, 71); color: #ff6347; color: tomato;
- White text
- 2.95:1 AA fail
- Black text
- 7.13:1 AA pass
Normal-size text needs a contrast of at least 4.5:1 to pass WCAG AA.
Some things to try:
- Turn all three sliders up to 255. What do you get?
- Turn them all down to 0.
- Put red and green all the way up, and blue all the way down. ๐คฏ
The mixer also tells you if words on your color are easy to read. Dark words on a light color, or light words on a dark color, are easiest for everyone's eyes.
Changing sizes
CSS can change sizes too. The font-size property sets how big the letters are. Sizes are often measured in px, which is short for pixels, the tiny dots that make up your screen.
h1 {
font-size: 50px;
}
Here are some more properties you can try:
| Property | What it changes | Try |
|---|---|---|
background-color | The color behind things | background-color: lightyellow; |
color | The color of the words | color: purple; |
font-size | How big the letters are | font-size: 40px; |
text-align | Left, middle or right | text-align: center; |
Paint your page
Now give this page a makeover! ๐๏ธ
Challenge
Give your page a makeover
The CSS tab already has two empty rules. Put properties inside the curly brackets { } to:
- Give the whole page (
body) a background color. Pick any color except white. - Give the big title (
h1) a color of its own. - Make the big title bigger with
font-size. It starts at 32px, so try something like 50px.
Bonus: center the title with text-align: center;
- Your page has a background color
- Your big title has a color of its own
- Your big title is bigger than before
What you learned
- CSS decides how a page looks: colors, sizes and more.
- A CSS rule has a selector (what to paint), a property (what to change) and a value (what to change it to).
- Screens make colors by mixing red, green and blue light, each from 0 to 255.
- Easy-to-read pages use dark words on light colors, or light words on dark colors.
- You gave your page a colorful makeover! ๐จ
Finished this lesson?
Mark it complete to track your progress on this device.