Skip to content
IGCSE·Tuition
ICT · Lesson

Use a stylesheet for consistent presentation

You change a heading colour on one page and then discover three other pages still show the old one.

On this page
  1. How does a CSS rule work?
  2. How do you build and link a stylesheet?
  3. Worked example
  4. The mistake to watch for
  5. Check yourself
  6. Where this leads next

A stylesheet is a separate file of rules that controls how pages look, so you change a colour or font once and every linked page follows. This skill appears when a task asks for consistent presentation across a page or a small site, and it builds on the page structure you have already written.

How does a CSS rule work?

A rule has a selector (what to style) and one or more declarations (how), each ending in a semicolon.

h1 {
  color: navy;
  font-family: Arial, sans-serif;
  font-size: 28px;
}

Here h1 is the selector. color, font-family and font-size are properties, and each is followed by a value. A missing semicolon is the most common reason a rule half works.

  1. Create a new plain text file named style.css in the site folder.
  2. Write one rule per selector, starting with the elements the task names.
  3. Save the file and keep its extension as .css.
  4. Add a link line inside the head of every page: <link rel="stylesheet" href="style.css">.
  5. Reload the page and check that each requirement now shows.

Worked example

An invented task asks for all level 2 headings to be dark green and 20 pixels tall, and all paragraphs in 16 pixel Arial.

Step 1: create style.css.

Step 2: write the two rules.

h2 {
  color: darkgreen;
  font-size: 20px;
}

p {
  font-family: Arial, sans-serif;
  font-size: 16px;
}

Step 3: in the head of index.html, add the link line. The stylesheet is in the same folder, so the path is simply style.css.

Step 4: if a second page, pages/events.html, also needs the rules, its link line is <link rel="stylesheet" href="../style.css">, because the stylesheet is one folder up. Later, changing darkgreen to navy once recolours every h2 on both pages.

The mistake to watch for

A common slip is to copy the same styling into the tag on every element.

<h2 style="color: darkgreen;">When we meet</h2>
<h2 style="color: darkgreen;">What we do</h2>

This works for now but fails the consistency goal: a later change needs an edit on every heading, and one will be missed. The correction is a single h2 rule in the stylesheet and plain <h2> tags on the page. A second, quieter mistake is a wrong path in the link line, which makes the whole stylesheet silently disappear.

Check yourself

1. Find the fault: p { color: red font-size: 14px; }

Show answer

There is no semicolon after red. Correct: p { color: red; font-size: 14px; }

2. A page in the pages folder links to style.css in the site folder. Write the correct href.

Show answer

../style.css, because the stylesheet is one folder above the page.

3. Four pages share one stylesheet. The client wants a different heading colour. How many files need editing?

Show answer

One: the stylesheet. All four pages follow it.

Where this leads next

Next, make the pages connect to each other in Create a working relative link. Return to the module guide, and check your result against the brief with the practical task and evidence checker.

A rule can make sense on its own and still fail once the files sit in different folders. A teacher in online one-to-one ICT tuition can check your paths and rules against your real files.

Questions people ask

What is the difference between internal and external CSS?

Internal CSS sits inside a style element in one page's head and affects only that page. External CSS lives in a separate file, such as style.css, and any page that links to it shares the same rules. Use external CSS when several pages must look consistent.

Where does the link element go?

Inside the head of each page, not the body. It reads link rel=stylesheet with an href that points to the CSS file. The href is a path, so it must change if the page sits in a different folder from the stylesheet.

Why use classes instead of styling each tag?

A class lets you apply one named rule to chosen elements only, such as a highlighted note. Tag rules such as h2 apply to every h2 on the page. Both go in the stylesheet, so a later change is still made in one place.

Updated:

Your next step

If your styles apply on one page but vanish on another, a one-to-one teacher can compare the two files with you and find the path or the rule that differs.

Paid one-hour trial at your assigned teacher’s confirmed rate, starting from RM80.

Tuition is arranged with a parent or guardian. Send them this page on WhatsApp and they can enquire for you.

Parents: enquire here

  • 9,000+ students helped through our service
  • 9+ years helping IGCSE students