By the end of this lesson you will be able to:
<div> for grouping and applying classes| Layer | Purpose | Typical Technologies |
|---|---|---|
| Content layer | Defines the structure and meaning of the page. | HTML5 elements, attributes, semantic tags, file paths. |
| Presentation layer | Controls visual appearance – colours, fonts, layout. | CSS (external, internal, inline), classes, IDs. |
| Behaviour layer | Provides interactivity (not assessed in IGCSE ICT 0417). | JavaScript, DOM scripting (outside the scope of this lesson). |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Brief description of the page">
<meta name="keywords" content="keyword1, keyword2, keyword3"> <!-- optional for modern SEO -->
<meta name="author" content="Your Name">
<title>Page title</title>
<link rel="stylesheet" href="css/style.css"> <!-- external CSS – relative path -->
<!-- Optional for legacy IE browsers: -->
<meta http-equiv="X-UA-Compatible" content="IE=edge">
</head>
<body>
…content…
</body>
</html>
UTF-8 to support all characters.css/style.css (relative to the current folder).https://example.com/css/style.css.<header> – site or page header.<nav> – navigation links.<section> – thematic grouping of content.<article> – self‑contained composition (e.g. blog post).<aside> – tangential content such as sidebars.<footer> – site or page footer.<h1> … <h6><p><strong>, <em>alt for accessibility):<img src="images/pic.jpg" alt="Descriptive text" width="300">
<audio controls>
<source src="audio/song.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
controls and provide poster where appropriate):<video width="480" controls poster="images/poster.jpg">
<source src="video/clip.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
<a href="page2.html">Next page</a>
<a href="https://example.com">External site</a>
<a href="mailto:teacher@example.com">Email teacher</a>
<a href="https://example.com" target="_blank">New tab</a>
<a id="section3"></a>
<a href="#section3">Jump to Section 3</a>
Use HTML for structure only; style entirely with CSS (HTML attributes such as border, cellspacing and cellpadding are deprecated).
<table class="tbl‑styled">
<thead>
<tr class="header‑row">
<th colspan="2">Product</th>
<th>Price</th>
</tr>
</thead>
<tbody>
<tr>
<td rowspan="2">Laptop</td>
<td>Model A</td>
<td>$800</td>
</tr>
<tr>
<td>Model B</td>
<td>$950</td>
</tr>
</tbody>
</table>
colspan="n" merges n columns.rowspan="n" merges n rows..tbl‑styled, .header‑row) to control size, background, alignment, spacing, padding and borders.<div>The <div> element has no semantic meaning but is ideal for applying a class or ID to a block of content.
<div class="sidebar">
<h2>Quick Links</h2>
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="contact.html">Contact</a></li>
</ul>
</div>
<link rel="stylesheet" href="css/style.css"><style> tags in the <head>style="color:#f00;" on an element (overrides external and internal rules)| Selector type | Specificity (a,b,c,d) | Example |
|---|---|---|
| Inline style | (1,0,0,0) | style="…" |
| ID selector | (0,1,0,0) | #mainHeader |
| Class, attribute, pseudo‑class | (0,0,1,0) | .highlight, [type="text"], :hover |
| Element selector | (0,0,0,1) | p, table |
When two rules have the same specificity, the later one in the stylesheet wins. !important overrides normal specificity but should be used sparingly.
color, font-family, font-size, line-height, text-align, etc.margin, padding, border, background, width, height.inherit keyword or by declaring the property explicitly on the child element..myClass { … }#myId { … }background-color – solid colour behind the element.background-image – url('path/to/image.png').background-repeat – repeat, repeat-x, repeat-y, no-repeat.background-position – e.g. center, top left, 50% 50%.background-size – cover, contain, or explicit dimensions (100px 50px).background-attachment – scroll (default) or fixed.color – text colour.font-family – e.g. Arial, Helvetica, sans-serif.font-size – px, em, rem, %.font-weight – normal, bold, 100‑900.font-style – normal, italic, oblique.text-align – left, center, right, justify.line-height – unitless multiplier (e.g. 1.5) or length value.width / height – set on table, tr, th, td.border-spacing – distance between cells when border-collapse: separate.padding – internal space inside a cell (replaces the old cellpadding attribute).margin – space outside the table.text-align – horizontal alignment of cell content (left, center, right, justify).vertical-align – top, middle, bottom, baseline.border – shorthand (border:2px solid #333;).border-collapse – collapse merges adjoining borders; separate keeps them distinct.border-style – none, solid, dashed, dotted, etc.border-color – any colour value.border-width – thickness (e.g., 1px).border:0; or border-style:none;.| HTML attribute | CSS equivalent | Notes |
|---|---|---|
cellpadding="10" | td, th { padding:10px; } | Controls internal cell space. |
cellspacing="5" | table { border-spacing:5px; } | Works only with border-collapse:separate. |
border="1" | table, th, td { border:1px solid #000; } | HTML attribute is deprecated; use CSS. |
/* ---------- 1. Background colours ---------- */
.bg-blue { background-color: #cce5ff; }
.bg-grey { background-color: #f2f2f2; }
/* ---------- 2. Background images ---------- */
.bg-pattern {
background-image: url('images/pattern.png');
background-repeat: repeat;
background-position: center;
background-size: auto;
}
/* ---------- 3. Font styling ---------- */
.text-large-bold {
color: #333333;
font-family: Arial, Helvetica, sans-serif;
font-size: 1.2em;
font-weight: bold;
}
/* ---------- 4. Table layout ---------- */
.table-collapsed {
border-collapse: collapse;
width: 100%;
}
/* ---------- 5. Table header row ---------- */
.header-row {
background-color: #333333;
color: #ffffff;
font-weight: bold;
border: 2px solid #000;
}
/* ---------- 6. Table data cell ---------- */
.td-center {
padding: 8px;
text-align: center;
vertical-align: middle;
border: 1px solid #999999;
}
/* ---------- 7. Alternate data cell ---------- */
.td-light {
background-color: #f2f2f2;
padding: 10px;
text-align: center;
vertical-align: middle;
border: 1px solid #cccccc;
}
/* ---------- 8. Sidebar grouping ---------- */
.sidebar {
background-color: #e9ecef;
padding: 15px;
border: 1px solid #ced4da;
}
| Context | Property | Typical Values | Result |
|---|---|---|---|
| Any block‑level element | background-color | colour name, #hex, rgb(), rgba() | Solid background colour. |
| Any block‑level element | background-image | url('path'), none | Image placed behind the element. |
| Any element | color | colour name, #hex, rgb() | Text colour (inherited). |
| Textual elements | font-family | Arial, Helvetica, sans-serif, etc. | Font face for the text. |
| Textual elements | font-size | px, em, rem, % | Size of the text. |
| Table, th, td | border | 1px solid #000 | Visible border around the element. |
| Table | border-collapse | collapse | separate | Controls whether adjoining borders merge. |
| Table | border-spacing | 0, 5px, 10px | Space between cells (only when separate). |
| th, td | padding | 5px, 10px | Internal space inside a cell. |
| th, td | text-align | left, center, right, justify | Horizontal alignment of cell content. |
| th, td | vertical-align | top, middle, bottom, baseline | Vertical alignment of cell content. |
Your generous donation helps us continue providing free Cambridge IGCSE & A-Level resources, past papers, syllabus notes, revision questions, and high-quality online tutoring to students across Kenya.