Year 9Technology 60 min
We are learning to
- We are learning to write CSS rules that style an HTML page.
- We are learning to explain why web developers keep content (HTML) and style (CSS) separate.
Success criteria: I can…
- I can link a stylesheet to an HTML page.
- I can write a CSS rule with a selector, properties and values, using correct punctuation.
- I can use a class selector to style one element differently from others.
- I can explain two reasons CSS matters, including readability and contrast.
Key competenciesThinkingUsing language, symbols and texts
Lesson sequence
60 min total- 1
Same page, two looks
Starter 0–8 minTeacher- Open the athletics day page in a browser with no stylesheet: black serif text running the full width of the screen.
- Then add the link line and refresh to show the styled version.
- Ask: What changed? (fonts, colours, spacing, width, the notice box)
- Ask: Did I change any of the words or headings? (no, only the stylesheet)
- Say: “HTML says what the content is. CSS says how it looks. Today you will write the CSS.”
- Tip: Show csszengarden.com, where one HTML page has been styled by hundreds of designers in completely different ways.
Students- Compare the two versions and list what changed.
- Answer the two questions.
HTML file<!DOCTYPE html> <html> <head> <title>Athletics Day</title> <link rel="stylesheet" href="style.css"> </head> <body> <h1>Year 9 Athletics Day</h1> <p class="notice">Bring your PE gear and a water bottle.</p> <h2>When and where</h2> <p>Friday at the school field, from 9 am to 2.30 pm.</p> <h2>Events</h2> <ul> <li>100 m sprint</li> <li>Long jump</li> <li>Shot put</li> </ul> <p>Parents and whānau are welcome to watch.</p> </body> </html>
- 2
Anatomy of a CSS rule
Main 8–18 minTeacher- Write on the board: h1 { color: #1b4d3e; font-size: 36px; }
- Label the selector (h1), the curly brackets, two properties (color, font-size), two values and the semicolons.
- Say: “Each property ends with a semicolon. Spelling is American: color, not colour.”
- Show a class rule: .notice { background-color: #fff3cd; padding: 8px; }
- Ask: Which element on our page will this rule style? (only the paragraph with class="notice")
- Questions
- 1.What is wrong with: h2 { color navy; } (the colon between the property and the value is missing, so the browser ignores it)
- 2.What is wrong with: h2 ( color: navy; ) (round brackets instead of curly brackets, so the rule is ignored)
- 3.What is wrong with: notice { padding: 8px; } (the class selector needs a full stop: .notice)
- 4.What is wrong with: p { colour: navy; } (property must be spelt color)
Students- Label the parts of a rule in their books.
- Spot the error in each of the four rules.
Whiteboard - 3
Style the page
Main 18–38 minTeacher- Students save the HTML file as index.html and a new empty file as style.css in the same folder (or paste the HTML into the HTML panel of CodePen and write CSS in the CSS panel, where the link line is not needed).
- Give the target rules on the screen and ask students to type them, saving and refreshing after each rule to see its effect:
- body { font-family: Arial, sans-serif; max-width: 700px; margin: 0 auto; padding: 16px; line-height: 1.5; background-color: #f4f7f0; color: #222222; }
- h1 { color: #1b4d3e; }
- h2 { color: #1b4d3e; border-bottom: 2px solid #1b4d3e; }
- .notice { background-color: #fff3cd; padding: 8px; font-weight: bold; }
- Ask: What did max-width and margin: 0 auto do? (stopped lines stretching across a wide screen and centred the page, which makes it easier to read)
- Then students make the page their own: change colours, the font and one more property of their choice.
- Tip: If nothing changes, check the file names match, both files are in the same folder, and you refreshed the browser.
Students- Create style.css and type the rules one at a time, refreshing after each.
- Customise colours, font and one extra property.
Devices with a plain text editor and browser, or CodePen Target rules on the screen - 4
Why it matters: one change, every page; and contrast
Main 38–50 minTeacher- Say: “Imagine the school site has 200 pages all linked to the same style.css. The school changes its colours.”
- Ask: Without CSS, how would you change every heading colour? (edit all 200 pages one by one)
- Ask: With CSS? (change one line in style.css and every page updates)
- Now contrast: change the body text colour to #999999 on a white background and ask students to read it from the back of the room.
- Say: “Guidelines for accessible websites ask for a contrast ratio of at least 4.5 to 1 for normal text. #999999 on white is about 2.8 to 1, so it fails. #767676 on white is about 4.5 to 1, which just passes. Black on white is 21 to 1.”
- Students test their own text and background colours in the free WebAIM Contrast Checker and fix any that fail.
Students- Answer the questions about the 200-page site.
- Test their colours in a contrast checker and change any that fail.
WebAIM Contrast Checker (free, in a browser) - 5
Exit check
Plenary 50–60 minTeacher- Students answer on an exit slip
- Questions
- 1.Write a CSS rule that makes every paragraph 18px with a line height of 1.6. (p { font-size: 18px; line-height: 1.6; })
- 2.Write a rule that gives only elements with class="results" a light grey background. (.results { background-color: #eeeeee; })
- 3.Give two reasons web developers keep style in a separate CSS file. (one change updates every page; HTML stays clean and easier to read; the same content can look different on phones, screens and print; designers and writers can work separately)
- 4.A student uses light yellow text on a white background. Explain the problem. (the contrast is too low, so many people, especially those with low vision, can't read it; it fails accessibility guidelines)
- Collect the slips. Students save both files with their name in the folder.
Students- Answer the four exit questions alone.
- Save their files.
Exit slips
Key vocabulary
CSS
Cascading Style Sheets: the language that controls how a web page looks, such as colours, fonts, spacing and layout.
selector
The part of a CSS rule that chooses which elements to style, for example h1 or .notice.
property
The feature being changed, such as color, font-size or padding.
value
The setting given to a property, such as 18px or #1b4d3e.
class
A name added to HTML elements (class="notice") so CSS can style just those elements, using a full stop in the selector (.notice).
contrast
How different the text colour is from the background colour. Low contrast makes text hard to read.
Differentiation
Support
- Give style.css with the body rule already written and the other rules as fill-in-the-gaps (h1 { color: ____; }), so students focus on one property at a time.
- Give a CSS card listing ten common properties with an example value for each (color, background-color, font-family, font-size, line-height, padding, margin, border, text-align, font-weight).
- Pair students so one reads each rule aloud while the other types, then swap halfway.
Extension
- Ask students to add a second page (results.html) linked to the same stylesheet and show that changing one rule restyles both pages.
- Ask students to add a rule for li elements inside the events list only, using a descendant selector (ul li) and explain why it doesn't affect paragraphs.
- Ask students to write a media query that makes the h1 smaller on screens narrower than 500px, and test it by resizing the browser.
Accessibility
- Use a larger editor font size and offer a high-contrast editor theme for students who need it.
- Provide the target rules as a printed sheet so students can work at their own pace without looking up at the screen.
- For English language learners, pre-teach selector, property, value and contrast with a labelled example rule, and point out that CSS uses American spelling (color, center).
Assessment
- Check during the styling step that every student has a linked stylesheet whose rules visibly change the page.
- Error-spotting questions in step 2 show whether students understand CSS punctuation and class selectors.
- Exit slip: questions 1 and 2 show correct rule syntax and class selectors; questions 3 and 4 show whether students can explain why CSS matters.
Resources
- HTML file for the athletics day page (in the starter step)
- Devices with a plain text editor and a browser, or CodePen
- Target rules and error-spotting questions on the screen
- WebAIM Contrast Checker
- Exit slips