Web Design & Development · CSS

WDD6 - CSS: getting started

Mon 23 Nov 2026 · P1+P2 (double)
Core lesson ~50-60 minutes · extra practice time available
Learning intentions
Success criteria
Warm up - HTML structure recap

CSS styles the semantic structure you built in WDD4.

WU1
Which semantic element contains the main navigation links?
 
WU2
What is CSS mainly used for?
  • HTML gives semantic structure.
  • Correct.
  • That is not the role of CSS.
  • JavaScript handles events later.
WU3
Which part of a CSS rule chooses which HTML elements will be styled?
  • A property is the feature being changed, such as color.
  • A value is the setting given to a property.
  • Correct. The selector chooses which elements are styled.
  • A declaration is a property-value pair, not the element chooser.

Key vocabulary

CSS
Cascading Style Sheets: rules that control appearance and layout.
Selector
The part of a CSS rule that chooses which HTML elements are styled.
Property
The feature being changed, such as color, background-color or font-size.
Value
The setting given to a property, such as blue, 20px or center.
Grouping selector
A selector that applies the same rule to several selectors separated by commas.
Descendant selector
A selector that targets an element inside another element, such as links inside nav.

Where CSS can be placed

Inline, internal and external CSS

CSS can be written in three places. Inline CSS is written directly on one HTML element using the style attribute. Internal CSS is written inside a <style> block in the page's head. External CSS is stored in a separate .css file and linked from the HTML page.

Inline

Fast for one-off testing, but hard to maintain. Example: style="color: blue".

Internal

Useful for one page. Rules sit in <style> in the head.

External

Best for a multi-page site, because many pages can share one stylesheet.

The cascade

"Cascading" means several CSS rules can apply to the same element. When rules conflict, the browser decides which one wins. At this stage, use this simple Higher-friendly rule: inline CSS beats internal CSS, and internal CSS beats external CSS when the selectors are otherwise equally specific.

Two more cascade situations come up in real pages. If two rules have exactly the same specificity and come from the same place - for example two rules in the same external stylesheet, two internal rules in the same page, or two separate linked stylesheets - the rule written or linked later wins, because the browser reads rules in order and applies each one as it reaches it. A declaration can also be marked !important to force it to override the normal cascade, but this should be used rarely: it makes a stylesheet much harder to override or maintain later, so conflicts should normally be solved through selector choice and rule order first, not by reaching for !important.

External CSS
p { color: green; }
Inline CSS on one paragraph
<p style="color: blue">

The paragraph will be blue.

Selectors

Example 1 - Basic CSS rule
h1 {
  color: #185FA5;
  font-size: 32px;
}
1
h1 is the selector: it chooses all h1 elements.
2
color and font-size are properties.
3
#185FA5 and 32px are values.
Example 2 - Grouping selector
h1, h2, h3 {
  font-family: Arial, sans-serif;
  color: #042C53;
}
OK
This is a grouping selector. The same declarations apply to h1, h2 and h3.
Example 3 - Descendant selector
nav a {
  color: white;
  text-decoration: none;
}
OK
This is a descendant selector. It targets <a> elements inside <nav>. WDD10 will use this pattern for navigation bars.

Practical: live CSS editor

Edit the CSS on the left and watch the preview on the right update instantly. Use it to test grouping and descendant selectors on real markup before you write them from memory below.

Your CSS
Try changing nav a to nav p — the links stop being styled, because there is no p inside nav.
Live preview
Now you try

Write the selector only:

  1. Style all h1 and h2 headings with the same rule.
  2. Style only links inside nav.
  1. h1, h2 - grouping selector
  2. nav a - descendant selector
Common mistakes
Exam tip

The SQA wording names both grouping selectors and descendant selectors. Use those exact terms. A comma means grouping; a space between selectors means descendant.

Task Set A - Core questions

Task Set A - Core questions
Complete all questions. Written answers reveal a model answer for self-assessment.
A1
What does CSS stand for?
 
A2
Which CSS placement is best for styling a multi-page website consistently?
  • This would be hard to maintain.
  • Better than inline, but still repeated.
  • Correct. One stylesheet can style many pages.
  • JavaScript is not CSS placement.
A3
Write a grouping selector for h1, h2 and h3.
 
A4
Write a descendant selector that targets links inside nav.
 
A5
If equally specific external, internal and inline CSS all set the same paragraph's colour differently, which wins?
  • Correct. Inline style on the element wins in this simplified cascade case.
  • External CSS is easiest to maintain, but does not win this conflict.
  • That is not the rule used here.
  • HTML is not a CSS rule.
A6
Explain the difference between a grouping selector and a descendant selector, using examples.
Model answer
A7
Fill the gap: when two equally specific rules come from the same stylesheet, the rule written ___ in the file wins.
 
A8
Which of these is a descendant selector, not a grouping selector?
  • The comma makes this a grouping selector.
  • Correct. The space targets a elements inside nav - a descendant selector.
  • Commas here make this a grouping selector across three element types.
  • This groups two class selectors with a comma.
A9
This CSS is meant to make both h1 and h2 red, but nothing changes colour when it runs. Find the bug and write the corrected CSS.
h1 h2 {
  color: red;
}
h1, h2 {
  color: red;
}

The original used a space, which makes it a descendant selector — it looks for an h2 nested inside an h1, which never happens on this page, so it matches nothing. A comma turns it into a grouping selector that applies to both.

Task Set B - Extension

Task Set B - Extension
Use the extra time in this double period for deeper cascade practice - and B4 below, your first WebStorm task on this site.
B1
An external stylesheet says p { color: green; }. An internal style block says p { color: purple; }. The selectors are equally specific. Which colour is used, and what would happen if an inline style also set the paragraph to red?
One possible answer
B2
A pupil adds !important to every CSS declaration because a stubborn style will not apply. Explain why this is a poor long-term habit, and suggest a better first step to try instead.
One possible answer
B3
A page links two external stylesheets in this order: reset.css first, then theme.css second. reset.css has p { color: black; } and theme.css has p { color: navy; }, both equally specific. Which colour applies, and why?
One possible answer
B4 - Practical (WebStorm)
Refactor Willow Bakery's homepage from inline CSS to an internal stylesheet, using a grouping selector and a descendant selector.
  1. Download WDD6_starter.html below.
  2. Open WebStorm and open the downloaded file (File > Open).
  3. Add a <style> block in <head> and follow the six TODO steps written as an HTML comment near the top of the file.
  4. Save the file, then open it in a browser to check the page still looks the same as it did with inline CSS - a correct refactor changes nothing visually.
Download WDD6_starter.html
<style>
  nav {
    background-color: #042C53;
    padding: 10px;
  }
  nav a {
    color: white;
    text-decoration: none;
    margin-right: 12px;
  }
  h1, h2 {
    font-family: Arial, sans-serif;
    color: navy;
  }
</style>

All three nav a links share one descendant selector; h1, h2 share one grouping selector. Every style="..." attribute in the body can now be deleted, since the same rules live in the stylesheet instead.

File this in OneNote under:
Higher Computing Science > Web Design & Development > WDD6

Teacher notes - Shift+T to toggle

Suggested timing: 8 min warm up, 15 min CSS placement/cascade, 15 min selectors, 15 min worked examples, 20 min Task Set A, remaining time Task Set B including B4.

Terminology watch: call nav a a descendant selector, not a child selector. WDD10 depends on this term being right.

Scope control: this lesson introduces CSS rule shape and selector types. Box model, float, margin, padding, height and width are WDD7-WDD9.

B4 is the first WebStorm task on this site. This lesson lands as an actual double period (see calendar.md/WDD.md §2a - planned as a single, but scheduled on a double), which is exactly why B4 exists: use the spare time to walk the class through downloading the starter file, opening it in WebStorm, and saving/checking it in a browser, before WDD7 expects them to do this independently under tighter time. Worth doing as a live demo on the board first if this is genuinely the pupils' first time in WebStorm.