Learn / Programming / Make it look good

So meanwhile... make it look good.

Use CSS to change colours, sizes and spacing, and watch the page change as you type.

10 minutes, beginner

CSS: make it look good

By the end you’ll be able to change the colour, size and background of things on a web page.

1. Say it

CSS is a list of rules. Each rule picks something on the page and says how it should look. Here are six properties to start with.

PropertyWhat it changesExample
colorThe colour of the textcolor: tomato;
background-colorThe colour behind somethingbackground-color: lightyellow;
font-sizeHow big the text isfont-size: 24px;
text-alignLeft, centre or righttext-align: center;
borderA line around somethingborder: 2px solid navy;
paddingSpace inside, around the contentpadding: 16px;

Tip: Colours can be names, like tomato, navy or gold, or codes like #ff6600. Note the American spelling: it’s color, not “colour”, and CSS won’t understand the British one.

2. Know it

A CSS rule has three parts. Look at h1 { color: tomato; }

  • The selector, here h1, says what to style.
  • The property, here color, says what to change.
  • The value, here tomato, says what to change it to.

The property and value sit inside curly brackets, are separated by a colon, and end with a semicolon.

HTML says what is on the page and CSS says how it looks. CSS stands for Cascading Style Sheets. “Cascading” means that when two rules disagree, there are fixed rules about which one wins, but you won’t need that today.

3. Use it

Edit the CSS and the page updates as you type. Then try the three challenges.

  • Challenge 1: change the heading’s color to something other than black.To do
  • Challenge 2: give the paragraph a background-color.To do
  • Challenge 3: set a font-size on anything, for example font-size: 24px;To do

Stuck? Inside the p { } brackets, add a line such as background-color: lightyellow; and don’t forget the semicolon.

The preview shows only what you type here. It can’t load anything from the internet, and nothing you type is saved or sent anywhere.

4. Check it

1. What does CSS stand for?

2. What does CSS control?

3. In h1 { color: red; }, what is h1?

4. Which property changes the colour of text?

5. What ends each line of a CSS rule, such as color: red?

Go further