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:

  • h1 is the selector. It selects, or picks, which parts of the page to paint. This one picks every <h1>.
  • color is the property. It's the thing you want to change.
  • blue is 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.

Question

Quick check

In the rule p { color: green; }, which part picks what gets painted?
Pick an answer.

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

CSS
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.

Question

Quick check

What color do you get with rgb(255, 255, 0): red and green light all the way up, and no blue?
Pick an answer.

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:

PropertyWhat it changesTry
background-colorThe color behind thingsbackground-color: lightyellow;
colorThe color of the wordscolor: purple;
font-sizeHow big the letters arefont-size: 40px;
text-alignLeft, middle or righttext-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:

  1. Give the whole page (body) a background color. Pick any color except white.
  2. Give the big title (h1) a color of its own.
  3. 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.