Web development

Style Studio

Give yesterday's page colours, fonts and boxes with CSS, and see how one file changes the whole look.

Day 2 45 to 60 minutes 7 steps Key Stage 3
Start step 1
style-studio/index.html

Yesterday's page was all black text on white. Today you will style it with CSS, the language of colour and layout. The HTML hardly changes: one new line links it to a stylesheet, and the stylesheet does the rest.

You will learn

  • Link a stylesheet to a page
  • Choose colours and fonts with CSS rules
  • Draw boxes with borders, padding and rounded corners
  • Style one element with a class

You will need

  • A computer with a web browser
  • The Web Studio, or Notepad
  • Day 1's page, or the one the Studio starts you with

Words to know

CSS
Cascading Style Sheets: the code for how a page looks.
rule
A selector and the properties it sets, such as h1 { color: red; }.
property
What to change, such as color or font-size.
class
A name you give elements so CSS can style them, such as class="intro".

Step by step

  1. Step 1: Link a stylesheet

    In the Web Studio, choose Day 2: Style Studio. It starts with the All About Me page and one new line in its <head>: a <link> to style.css.

    Click the style.css tab. A CSS rule names what to style, then lists properties and values between curly brackets. This rule changes the font of the whole body.

    index.htmlHTML
    <!DOCTYPE html><html>  <head>    <meta charset="utf-8">    <title>All about me</title>    <link rel="stylesheet" href="style.css">  </head>  <body>    <h1>Hi, I am Sam! &#128075;</h1>    <p>I am in Year 7 and I love <strong>coding</strong>, football and <em>very</em> loud music.</p>     <h2>My favourite things</h2>    <ul>      <li>Food: pizza</li>      <li>Animal: otter</li>      <li>Colour: green</li>    </ul>     <h2>Three facts about me</h2>    <ol>      <li>I have two cats.</li>      <li>I can juggle three balls.</li>      <li>I once ate ten pancakes.</li>    </ol>     <hr>     <h2>A website I like</h2>    <p>I learn new things at <a href="https://www.bbc.co.uk/bitesize">BBC Bitesize</a>.</p>  </body></html>
    style.cssCSS
    body {  font-family: Arial, sans-serif;}
    style-studio/index.html
    The same page in a cleaner font.
  2. Step 2: Add some colour

    Give the page a cream background and dark grey writing, then colour the headings. Colours can be names such as green, or codes such as #b4461e: a # and six digits for how much red, green and blue to mix.

    New: lines 3, 4 and 6 to 13.

    style.cssCSS
    body {  font-family: Arial, sans-serif;  background: #fff8e7;  color: #333333;} h1 {  color: #b4461e;} h2 {  color: #2f7d32;}
    style-studio/index.html
    A cream page with coloured headings.
    Watch out Every property ends with a semicolon, and every rule ends with }. One missing } can stop all the rules after it from working.
  3. Step 3: A big centred heading

    Make the main heading bigger and put it in the middle of the page.

    New: lines 9 and 10.

    style.cssCSS
    body {  font-family: Arial, sans-serif;  background: #fff8e7;  color: #333333;} h1 {  color: #b4461e;  font-size: 48px;  text-align: center;} h2 {  color: #2f7d32;}
    style-studio/index.html
    The heading is big and centred.
    Tip CSS uses the American spelling: color and center.
  4. Step 4: Boxes round the lists

    One rule can style several things: ul, ol means both kinds of list. A border draws a line round each, border-radius rounds its corners, and padding adds space inside it.

    New: lines 16 to 22.

    style.cssCSS
    body {  font-family: Arial, sans-serif;  background: #fff8e7;  color: #333333;} h1 {  color: #b4461e;  font-size: 48px;  text-align: center;} h2 {  color: #2f7d32;} ul, ol {  background: white;  border: 3px solid #f4a259;  border-radius: 12px;  padding: 16px 40px;}
    style-studio/index.html
    Each list sits in a white box with an orange border.
  5. Step 5: A class for the introduction

    To style just one paragraph, give it a class in the HTML: class="intro". In CSS, a class name starts with a dot.

    New: line 10.

    index.htmlHTML
    <!DOCTYPE html><html>  <head>    <meta charset="utf-8">    <title>All about me</title>    <link rel="stylesheet" href="style.css">  </head>  <body>    <h1>Hi, I am Sam! &#128075;</h1>    <p class="intro">I am in Year 7 and I love <strong>coding</strong>, football and <em>very</em> loud music.</p>     <h2>My favourite things</h2>    <ul>      <li>Food: pizza</li>      <li>Animal: otter</li>      <li>Colour: green</li>    </ul>     <h2>Three facts about me</h2>    <ol>      <li>I have two cats.</li>      <li>I can juggle three balls.</li>      <li>I once ate ten pancakes.</li>    </ol>     <hr>     <h2>A website I like</h2>    <p>I learn new things at <a href="https://www.bbc.co.uk/bitesize">BBC Bitesize</a>.</p>  </body></html>

    New: lines 23 to 29.

    style.cssCSS
    body {  font-family: Arial, sans-serif;  background: #fff8e7;  color: #333333;} h1 {  color: #b4461e;  font-size: 48px;  text-align: center;} h2 {  color: #2f7d32;} ul, ol {  background: white;  border: 3px solid #f4a259;  border-radius: 12px;  padding: 16px 40px;} .intro {  font-size: 20px;  background: #ffe0b2;  padding: 12px;  border-radius: 8px;}
    style-studio/index.html
    The introduction stands out in a box of its own.
  6. Step 6: A link that lights up

    Style the link, then add a rule for a:hover, which only applies while the mouse is over the link. Point at the link in the preview to try it.

    New: lines 30 to 38.

    style.cssCSS
    body {  font-family: Arial, sans-serif;  background: #fff8e7;  color: #333333;} h1 {  color: #b4461e;  font-size: 48px;  text-align: center;} h2 {  color: #2f7d32;} ul, ol {  background: white;  border: 3px solid #f4a259;  border-radius: 12px;  padding: 16px 40px;} .intro {  font-size: 20px;  background: #ffe0b2;  padding: 12px;  border-radius: 8px;} a {  color: #b4461e;  font-weight: bold;} a:hover {  background: yellow;}
    style-studio/index.html
    Point at the link: it turns yellow.
  7. Step 7: Keep it readable

    Lines of text that stretch across a wide screen are hard to read. max-width stops the page growing wider than 700 pixels, and margin: 0 auto puts it in the middle.

    New: lines 5 to 7.

    style.cssCSS
    body {  font-family: Arial, sans-serif;  background: #fff8e7;  color: #333333;  max-width: 700px;  margin: 0 auto;  padding: 20px;} h1 {  color: #b4461e;  font-size: 48px;  text-align: center;} h2 {  color: #2f7d32;} ul, ol {  background: white;  border: 3px solid #f4a259;  border-radius: 12px;  padding: 16px 40px;} .intro {  font-size: 20px;  background: #ffe0b2;  padding: 12px;  border-radius: 8px;} a {  color: #b4461e;  font-weight: bold;} a:hover {  background: yellow;}
    style-studio/index.html
    The finished page, styled.

Test it

Tick each one when it works. If one does not, look back at the step it comes from.

Stretch challenges

Finished early? Try these. Each one has a hint if you get stuck.

  1. Your colours

    Change every colour to make the page match your favourite team, game or season.

    Show a hint

    Search for a colour picker, or try names such as tomato, teal, gold and orchid.

  2. A fancy font

    Use a different font for the headings than for the rest of the page.

    Show a hint

    Add font-family to the h1, h2 rule. Fonts most computers have include Georgia, Verdana, "Comic Sans MS" and "Courier New".

  3. Dark mode

    Make a dark version of the page: dark background, light text.

    Show a hint

    Change the body background to a dark colour such as #1e1e2e and its color to #f0f0f0. Then check every other colour still shows up.

The finished code

Show the whole page
index.htmlHTML
<!DOCTYPE html><html>  <head>    <meta charset="utf-8">    <title>All about me</title>    <link rel="stylesheet" href="style.css">  </head>  <body>    <h1>Hi, I am Sam! &#128075;</h1>    <p class="intro">I am in Year 7 and I love <strong>coding</strong>, football and <em>very</em> loud music.</p>     <h2>My favourite things</h2>    <ul>      <li>Food: pizza</li>      <li>Animal: otter</li>      <li>Colour: green</li>    </ul>     <h2>Three facts about me</h2>    <ol>      <li>I have two cats.</li>      <li>I can juggle three balls.</li>      <li>I once ate ten pancakes.</li>    </ol>     <hr>     <h2>A website I like</h2>    <p>I learn new things at <a href="https://www.bbc.co.uk/bitesize">BBC Bitesize</a>.</p>  </body></html>
style.cssCSS
body {  font-family: Arial, sans-serif;  background: #fff8e7;  color: #333333;  max-width: 700px;  margin: 0 auto;  padding: 20px;} h1 {  color: #b4461e;  font-size: 48px;  text-align: center;} h2 {  color: #2f7d32;} ul, ol {  background: white;  border: 3px solid #f4a259;  border-radius: 12px;  padding: 16px 40px;} .intro {  font-size: 20px;  background: #ffe0b2;  padding: 12px;  border-radius: 8px;} a {  color: #b4461e;  font-weight: bold;} a:hover {  background: yellow;}
Notes for the teacher

Timing

  1. 10 minutes: step 1. Explain the shape of a rule on the board: selector, braces, property, colon, value, semicolon.
  2. 30 minutes: steps 2 to 6.
  3. 10 minutes: step 7, the tests, and a gallery walk to see each other's colours.

Mistakes to look out for

  1. colour and centre: CSS ignores properties and values it does not recognise, so nothing happens and there is no error.
  2. A missing ; or }: the rule, and sometimes the rules after it, stop working.
  3. .intro in the CSS but class="Intro" in the HTML: class names must match exactly.
  4. The stylesheet not linked: in Notepad, check that style.css is in the same folder as index.html.

Going further

The page's content and its look are now separate. Show how changing one file restyles every page that links to it: that is how a whole website stays consistent.