21.3

Topic 21

Use stylesheets

  • IGCSE I.C.T 0417
  • 2 min read
  • Syllabus 2026, 2027 and 2028

Objectives

  1. 1

    Use CSS in the presentation layer

    • aCreate the presentation layer of a web page
    • bCreate generic external styles and inline style attributes including: background properties including colour, images; font properties; table, table row, table header and table data properties including size, background colour, horizontal and vertical alignment, spacing, padding, borders: including collapsed, colour, thickness, visible/invisible
    • cCreate classes including: background properties including colour, images; font properties; table, table row and table data properties including size, background colour, horizontal and vertical alignment, spacing, padding, borders: including collapsed, colour, thickness, visible/invisible
    • dCreate external styles to be tagged in a web page including h1, h2, h3, p, li
    • eSpecify the font properties including font family, size, colour, alignment, bold, italic
    • fAttach comments to an external stylesheet
    • gSave styles in cascading stylesheet format
  2. 2

    The use of CSS in the presentation layer

    • aCharacteristics of cascading stylesheets including the difference between attached stylesheets and inline style attributes, the hierarchy of multiple attached stylesheets and inline styles within a web page
    • bCharacteristics of a style and a class including the difference between them
    • cReason relative file paths must be used for attached stylesheets

Cambridge IGCSE ICT 0417 syllabus 2026-2028, 21.3 Use stylesheets (copied for internal use as permitted by Cambridge)

Detailed · Deep study

1Creating styles

/* main.css - house style for Rivers Hotel */
body  { background-color: #f4f8fb; font-family: Arial, sans-serif; }
h1    { font-family: Georgia, serif; font-size: 28px; color: #003366; text-align: center; }
h2    { font-size: 20px; color: #006699; }
p     { font-size: 14px; }
li    { font-style: italic; }
table { border-collapse: collapse; width: 80%; }
th, td { border: 2px solid #003366; padding: 6px; text-align: left; vertical-align: top; }
th    { background-color: #cce0f0; font-weight: bold; }
.offer { background-image: url("../images/stripe.png"); color: #990000; }
An external stylesheet with comments, element styles, table properties and a class (relative path for the background image).
<p style="color: red; font-weight: bold;">Fully booked in December</p>
<p class="offer">Special offer</p>
An inline style attribute (applies to one element only) and a class applied to an element.
Attached (external) stylesheetInline style attribute
wherea separate .css file linked in the headinside the opening tag of one element
applies toevery page that links to itthat one element only
advantagesconsistent style across a whole site; change one file to restyle every pagequick, one-off change
prioritylowerhighest – overrides attached styles
StyleClass
whatformatting applied to an HTML element (e.g. every h1 or p)a named set of formatting (e.g. .offer) applied only to the elements given that class
used byall elements of that type automaticallyadding class="offer" to chosen elements
exampleh1 { color: navy; }.offer { color: red; }

2The cascade and file paths

When several stylesheets are attached, the one attached last has the highest priority if styles conflict; inline styles have priority over all attached stylesheets. Stylesheets must be attached using relative file paths (e.g. styles/main.css) so they still work when the site is uploaded to a web server or moved to another computer.

3Exam focus

Key words: CSS; external stylesheet; inline style; class; property; font-family; border-collapse; padding; comment; cascade; relative path.

Quick self-check

Answer in your head first, then reveal.

  1. A style is applied to all elements of a type, e.g. every h1 (1); a class is applied only to elements given that class name (1).

  2. The one attached last/lower in the head (1).

  3. h2 { color: blue; font-size: 18px; text-align: center; } (3).

Finished this subtopic? Track it on your subject page.