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.
| Property | What it changes | Example |
|---|---|---|
color | The colour of the text | color: tomato; |
background-color | The colour behind something | background-color: lightyellow; |
font-size | How big the text is | font-size: 24px; |
text-align | Left, centre or right | text-align: center; |
border | A line around something | border: 2px solid navy; |
padding | Space inside, around the content | padding: 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
colorto something other than black.To do - Challenge 2: give the paragraph a
background-color.To do - Challenge 3: set a
font-sizeon anything, for examplefont-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
Done!
You’ve styled a real web page with your own CSS.