Be able to create external styles to be tagged in a web page including h1, h2, h3, p, li

Published by Patrick Mutisya · 14 days ago

IGCSE ICT 0417 – Website Authoring: External Stylesheets

Topic: 21 Website authoring

Objective

Be able to create external styles to be tagged in a web page including h1, h2, h3, p and li.

What is an external stylesheet?

An external stylesheet is a separate file (normally with a .css extension) that contains all the style rules for one or more web pages. Keeping the CSS in its own file makes the site easier to maintain, reduces page size, and allows the same style to be applied to many pages.

Linking an external stylesheet

To apply an external stylesheet to an HTML document, place a <link> element inside the <head> section of the page.

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<title>My Web Page</title>

<link rel="stylesheet" href="styles.css">

</head>

<body>

</body>

</html>

Basic CSS selectors for common tags

The following table shows the simplest selectors that target the required HTML elements.

SelectorHTML element(s) affectedTypical use
h1All <h1> headingsMain page title – larger font, bold, centred
h2All <h2> headingsSection headings – slightly smaller than h1
h3All <h3> headingsSub‑section headings – smaller than h2
pAll paragraph elements (<p>)Body text – line‑height, margin, font‑size
liAll list items (<li>)Bullet or numbered list styling

Example: Styling headings, paragraphs and list items

Save the following code in a file called styles.css. The rules illustrate how each selector can be used.

/* styles.css */

/* 1. Main page title */

h1 {

font-family: Arial, sans-serif;

font-size: 2.5rem;

color: #003366;

text-align: center;

margin-top: 0;

}

/* 2. Section headings */

h2 {

font-family: Verdana, sans-serif;

font-size: 2rem;

color: #006699;

margin-bottom: 0.5rem;

}

/* 3. Sub‑section headings */

h3 {

font-family: Georgia, serif;

font-size: 1.5rem;

color: #0099CC;

margin-top: 1rem;

}

/* 4. Paragraph text */

p {

font-family: "Times New Roman", Times, serif;

font-size: 1rem;

line-height: 1.5;

color: #333333;

margin-bottom: 1rem;

}

/* 5. List items */

li {

font-family: Helvetica, sans-serif;

font-size: 0.95rem;

color: #444444;

margin-left: 1.5rem;

}

Practice exercise

  1. Create a new folder called website on your computer.
  2. Inside the folder, create two files: index.html and styles.css.
  3. Copy the <link> example from the “Linking an external stylesheet” section into the index.html file.
  4. Add at least one <h1>, two <h2>, one <h3>, two paragraphs, and an ordered list with three items.
  5. Paste the CSS example into styles.css and save both files.
  6. Open index.html in a web browser. Observe how the external stylesheet controls the appearance of each element.
  7. Experiment by changing a property (e.g., colour or font‑size) in styles.css and refresh the browser to see the effect.

Suggested diagram: Flow of linking an external CSS file to an HTML page, showing the <link> element in the head, the separate styles.css file, and the rendered page.