Lesson 6 of 14 · 8 min

Style it with CSS

HTML says what things are: a heading, a paragraph, a list. CSS says how they look: colours, sizes, spacing. Keeping the two apart means you can restyle a whole site without touching its content.

CSS lives in its own file, here called style.css. Look at the <head> of index.html: this line connects the two files.

<link rel="stylesheet" href="style.css">

A CSS file is a list of rules. Each rule picks some elements and says how they should look:

h1 {
  color: crimson;
  font-size: 40px;
}
  • h1 is the selector: this rule applies to every <h1> on the page.
  • Inside the curly braces are declarations: a property, a colon, a value, and a semicolon.
  • color sets the text colour. CSS understands 140 colour names, like crimson, navy and linen.
  • font-size sets the text size. px means pixels.

Open the style.css tab above the editor to write your CSS.

Your task

In style.css:

  1. Make the h1 text colour crimson.
  2. Make paragraph (p) text 18px big.
  3. Give the whole page (body) the background colour linen, using the background-color property.

Write all three rules in style.css, not in index.html.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>My styled page</title>
  <link rel="stylesheet" href="style.css">
</head>
<body>
  <h1>Hello, CSS!</h1>
  <p>This page gets its looks from a separate file called style.css.</p>
  <p>Change the rules there and watch this page change.</p>
</body>
</html>

Your page

Discussion

Stuck? Ask here. Be kind, and share hints rather than full answers.

Loading the discussion…