How to use it. In Tasks, the page you're building (Harbour Kayaks, a kayak hire firm on Auckland's Waitematā Harbour) is index.html, and its attached stylesheet is styles.css. Edit either one and the preview updates as you type. Each task is checked automatically by looking at the preview itself: what's in it and how it's styled. Choose Target above the preview to see what you're aiming for. The other views explain the three layers, paths and links, and the cascade.
The three layers of a web page.
- The content layer is the HTML: the text, images, tables and links, and the structure (headings, paragraphs, lists).
- The presentation layer is the CSS: how it looks (fonts, colours, borders, spacing, alignment).
- The behaviour layer is scripting (JavaScript): what happens when the user does something.
Keeping them separate means one stylesheet can give a whole website the same house style, and changing the stylesheet restyles every page.
The head and the body. The head holds information about the page: its <title> (shown in the browser tab, not on the page), the attached stylesheets (<link rel="stylesheet" href="styles.css">), and meta tags (charset, description, keywords, author, viewport). Everything shown on the page goes in the body.
Paths. A relative path (images/kayak.png, ../contact.html) is worked out from the folder the page is in, so it still works when the whole website is uploaded to a web server. An absolute path gives the full location: an absolute file path (C:\Users\Aroha\…) only exists on one computer, so don't use one in a website. An absolute URL (https://…) is right for linking to another website.
Hyperlinks. A link to a bookmark (an anchor) on the same page uses # and the element's id: <a href="#prices"> goes to <h2 id="prices">. target="_blank" opens a link in a new tab or window; mailto: opens an email to that address. An image inside <a> becomes a link.
The cascade. Styles can be attached (an external stylesheet), embedded (a <style> element in the head) or inline (a style attribute on one element). When they disagree, inline wins, then embedded, then attached. (Strictly, between the attached and embedded styles the later one wins, which is why the stylesheet is attached first. With several attached stylesheets, the last one attached wins.) A class (.warning) can be used by many elements; an id (#footer) must be unique on the page.
Common exam mistakes: putting the title in the body; forgetting the generic font family (Verdana, sans-serif); confusing points and pixels (24pt is 32px); using an absolute file path to an image on your own computer; leaving out the # in a bookmark link, or a capital letter that doesn't match the id; forgetting mailto:; changing only the width of an image so it's distorted; using the same id twice where a class is needed; empty or useless alt text ("image").
Objective: Cambridge IGCSE ICT (0417), section 21, website authoring: the web development layers, creating content (head, body, tables, images, hyperlinks, bookmarks), relative and absolute file paths, and the presentation layer (attached, embedded and inline styles, their hierarchy, classes and ids).
Where this fits
- Cambridge: Cambridge IGCSE Information and Communication Technology (0417)
- NCEA Level 1 Digital Technologies: 92005 Develop a digital technologies outcome
- NCEA Level 2 Digital Technologies: 91893 Use advanced techniques to develop a digital media outcome
- Pearson Edexcel International: Edexcel International GCSE ICT (4IT1); Edexcel International A Level Information Technology Goes beyond Edexcel International GCSE ICT (4IT1): Stylesheets and the cascade go beyond 4IT1, which uses HTML only for links, images and font enhancements.