Web development
Style Studio
Give yesterday's page colours, fonts and boxes with CSS, and see how one file changes the whole look.
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
colororfont-size. - class
- A name you give elements so CSS can style them, such as
class="intro".
Step by step
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>tostyle.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.1<!DOCTYPE html>2<html>3 <head>4 <meta charset="utf-8">5 <title>All about me</title>6 <link rel="stylesheet" href="style.css">7 </head>8 <body>9 <h1>Hi, I am Sam! 👋</h1>10 <p>I am in Year 7 and I love <strong>coding</strong>, football and <em>very</em> loud music.</p>11 12 <h2>My favourite things</h2>13 <ul>14 <li>Food: pizza</li>15 <li>Animal: otter</li>16 <li>Colour: green</li>17 </ul>18 19 <h2>Three facts about me</h2>20 <ol>21 <li>I have two cats.</li>22 <li>I can juggle three balls.</li>23 <li>I once ate ten pancakes.</li>24 </ol>25 26 <hr>27 28 <h2>A website I like</h2>29 <p>I learn new things at <a href="https://www.bbc.co.uk/bitesize">BBC Bitesize</a>.</p>30 </body>31</html>1body {2 font-family: Arial, sans-serif;3}The same page in a cleaner font. 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.
1body {2 font-family: Arial, sans-serif;3 background: #fff8e7;4 color: #333333;5}6 7h1 {8 color: #b4461e;9}10 11h2 {12 color: #2f7d32;13}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.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.
1body {2 font-family: Arial, sans-serif;3 background: #fff8e7;4 color: #333333;5}6 7h1 {8 color: #b4461e;9 font-size: 48px;10 text-align: center;11}12 13h2 {14 color: #2f7d32;15}The heading is big and centred. Tip CSS uses the American spelling:colorandcenter.Step 4: Boxes round the lists
One rule can style several things:
ul, olmeans both kinds of list. Aborderdraws a line round each,border-radiusrounds its corners, andpaddingadds space inside it.New: lines 16 to 22.
1body {2 font-family: Arial, sans-serif;3 background: #fff8e7;4 color: #333333;5}6 7h1 {8 color: #b4461e;9 font-size: 48px;10 text-align: center;11}12 13h2 {14 color: #2f7d32;15}16 17ul, ol {18 background: white;19 border: 3px solid #f4a259;20 border-radius: 12px;21 padding: 16px 40px;22}Each list sits in a white box with an orange border. 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.
1<!DOCTYPE html>2<html>3 <head>4 <meta charset="utf-8">5 <title>All about me</title>6 <link rel="stylesheet" href="style.css">7 </head>8 <body>9 <h1>Hi, I am Sam! 👋</h1>10 <p class="intro">I am in Year 7 and I love <strong>coding</strong>, football and <em>very</em> loud music.</p>11 12 <h2>My favourite things</h2>13 <ul>14 <li>Food: pizza</li>15 <li>Animal: otter</li>16 <li>Colour: green</li>17 </ul>18 19 <h2>Three facts about me</h2>20 <ol>21 <li>I have two cats.</li>22 <li>I can juggle three balls.</li>23 <li>I once ate ten pancakes.</li>24 </ol>25 26 <hr>27 28 <h2>A website I like</h2>29 <p>I learn new things at <a href="https://www.bbc.co.uk/bitesize">BBC Bitesize</a>.</p>30 </body>31</html>New: lines 23 to 29.
1body {2 font-family: Arial, sans-serif;3 background: #fff8e7;4 color: #333333;5}6 7h1 {8 color: #b4461e;9 font-size: 48px;10 text-align: center;11}12 13h2 {14 color: #2f7d32;15}16 17ul, ol {18 background: white;19 border: 3px solid #f4a259;20 border-radius: 12px;21 padding: 16px 40px;22}23 24.intro {25 font-size: 20px;26 background: #ffe0b2;27 padding: 12px;28 border-radius: 8px;29}The introduction stands out in a box of its own. 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.
1body {2 font-family: Arial, sans-serif;3 background: #fff8e7;4 color: #333333;5}6 7h1 {8 color: #b4461e;9 font-size: 48px;10 text-align: center;11}12 13h2 {14 color: #2f7d32;15}16 17ul, ol {18 background: white;19 border: 3px solid #f4a259;20 border-radius: 12px;21 padding: 16px 40px;22}23 24.intro {25 font-size: 20px;26 background: #ffe0b2;27 padding: 12px;28 border-radius: 8px;29}30 31a {32 color: #b4461e;33 font-weight: bold;34}35 36a:hover {37 background: yellow;38}Point at the link: it turns yellow. Step 7: Keep it readable
Lines of text that stretch across a wide screen are hard to read.
max-widthstops the page growing wider than 700 pixels, andmargin: 0 autoputs it in the middle.New: lines 5 to 7.
1body {2 font-family: Arial, sans-serif;3 background: #fff8e7;4 color: #333333;5 max-width: 700px;6 margin: 0 auto;7 padding: 20px;8}9 10h1 {11 color: #b4461e;12 font-size: 48px;13 text-align: center;14}15 16h2 {17 color: #2f7d32;18}19 20ul, ol {21 background: white;22 border: 3px solid #f4a259;23 border-radius: 12px;24 padding: 16px 40px;25}26 27.intro {28 font-size: 20px;29 background: #ffe0b2;30 padding: 12px;31 border-radius: 8px;32}33 34a {35 color: #b4461e;36 font-weight: bold;37}38 39a:hover {40 background: yellow;41}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.
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,goldandorchid.A fancy font
Use a different font for the headings than for the rest of the page.
Show a hint
Add
font-familyto theh1, h2rule. Fonts most computers have includeGeorgia,Verdana,"Comic Sans MS"and"Courier New".Dark mode
Make a dark version of the page: dark background, light text.
Show a hint
Change the
bodybackground to a dark colour such as#1e1e2eand itscolorto#f0f0f0. Then check every other colour still shows up.
The finished code
Show the whole page
1<!DOCTYPE html>2<html>3 <head>4 <meta charset="utf-8">5 <title>All about me</title>6 <link rel="stylesheet" href="style.css">7 </head>8 <body>9 <h1>Hi, I am Sam! 👋</h1>10 <p class="intro">I am in Year 7 and I love <strong>coding</strong>, football and <em>very</em> loud music.</p>11 12 <h2>My favourite things</h2>13 <ul>14 <li>Food: pizza</li>15 <li>Animal: otter</li>16 <li>Colour: green</li>17 </ul>18 19 <h2>Three facts about me</h2>20 <ol>21 <li>I have two cats.</li>22 <li>I can juggle three balls.</li>23 <li>I once ate ten pancakes.</li>24 </ol>25 26 <hr>27 28 <h2>A website I like</h2>29 <p>I learn new things at <a href="https://www.bbc.co.uk/bitesize">BBC Bitesize</a>.</p>30 </body>31</html>1body {2 font-family: Arial, sans-serif;3 background: #fff8e7;4 color: #333333;5 max-width: 700px;6 margin: 0 auto;7 padding: 20px;8}9 10h1 {11 color: #b4461e;12 font-size: 48px;13 text-align: center;14}15 16h2 {17 color: #2f7d32;18}19 20ul, ol {21 background: white;22 border: 3px solid #f4a259;23 border-radius: 12px;24 padding: 16px 40px;25}26 27.intro {28 font-size: 20px;29 background: #ffe0b2;30 padding: 12px;31 border-radius: 8px;32}33 34a {35 color: #b4461e;36 font-weight: bold;37}38 39a:hover {40 background: yellow;41}Notes for the teacher
Timing
- 10 minutes: step 1. Explain the shape of a rule on the board: selector, braces, property, colon, value, semicolon.
- 30 minutes: steps 2 to 6.
- 10 minutes: step 7, the tests, and a gallery walk to see each other's colours.
Mistakes to look out for
colourandcentre: CSS ignores properties and values it does not recognise, so nothing happens and there is no error.- A missing
;or}: the rule, and sometimes the rules after it, stop working. .introin the CSS butclass="Intro"in the HTML: class names must match exactly.- The stylesheet not linked: in Notepad, check that
style.cssis in the same folder asindex.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.