Skip to the page
Year 10 · ICT · Summer 2 · Website authoring and images; the Year 10 mock

HTML structure, tables and lists

PracticalPresent ▶

What this lesson covers

21.2a HTML structure and the head

Cambridge IGCSE ICT 0417 · Topic 21: Website authoring · Paper 3

21.2b HTML body: text, tables and media

Cambridge IGCSE ICT 0417 · Topic 21: Website authoring · Paper 3

You will learn to

  • Write the basic structure of an HTML page with correctly nested tags.
  • Add a title and meta tags in the head.
  • Mark up headings, paragraphs and lists.
  • Build a table with merged cells, using rowspan and colspan.

Success criteria

  • I can write the html, head and body tags in the right order and nesting.
  • I can build a table that matches the specification, including merged cells.
  • I can use h1, h2 and h3 exactly as the specification asks.
The syllabus points for these sections
  • Write the basic structure of an HTML page with correctly nested tags.
  • Add a title and attach an external stylesheet with a relative path.
  • Add meta tags for charset, description, keywords, author and viewport.
  • Set a default target window with the base element.
  • Mark up headings, paragraphs and ordered and unordered lists.
  • Group content with div elements and classes.
  • Build tables with th, td, rowspan and colspan, and set sizes in pixels or %.
  • Insert images, sound and video with alt text, sizes and controls.

Key words

Say each word, then read what it means. Every one is in the glossary too.

HTML
HyperText Markup Language: the language of the content layer of a web page.
CSS
Cascading Style Sheets: the language of the presentation layer, which sets how a page looks.
Tag
A word in angle brackets, such as `<p>`, that marks the start or end of an element.
Attribute
Extra information inside an opening tag, written name="value", such as src or alt.
Head
The part of a page holding information about it: title, meta tags, stylesheet links.
Meta tag
A head element that gives data about the page, such as charset, description or viewport.
External stylesheet
A separate .css file attached to pages with the link element.
Class
A label given to elements with the class attribute so CSS can style them as a group.
Bookmark
A named place on a page, made with an id, that a hyperlink can jump to.
Relative path
A file location described from the current file's folder, such as images/logo.png.
Absolute path
A full file location from the very start, such as a full URL or C:/...
Target
The attribute that sets which window a link opens in, such as _blank.
colspan / rowspan
Attributes that make a table cell stretch across columns or down rows.
Padding
The space inside an element or cell between its border and its content.
Alt text
Alternative text for an image, read by screen readers and shown if the image fails.

The explanation

Read it here, or open the study page below to go one step at a time with things to try.

21.2a HTML structure and the head

Tags, attributes and the page skeleton

HTML uses tags in angle brackets. Most come in pairs: an opening tag `<p>` and a closing tag `</p>`. The content goes between them.

An attribute gives extra information inside an opening tag, as name="value". In `<img src="images/logo.png">`, src is the attribute.

Every page has the same skeleton: `<!DOCTYPE html>`, then `<html>` with a `<head>` and a `<body>` inside it.

The head holds information about the page. The body holds everything the visitor sees.

<!DOCTYPE html>
<html lang="en">
<head>
    <!-- information about the page goes here -->
</head>
<body>
    <!-- everything the visitor sees goes here -->
    <h1>Café Retiro</h1>
    <p>Coffee and cakes next to Retiro Park.</p>
</body>
</html>
!Watch out

Close tags in the reverse order you opened them. `<p><b>Hi</p></b>` is wrong. `<p><b>Hi</b></p>` is right. Wrongly nested tags can lose the mark for that element.

The title

The `<title>` element goes in the head. Its text appears on the browser tab, in bookmarks and in search results.

It is not shown on the page itself. A heading on the page needs `<h1>`.

<head>
    <title>Café Retiro | Home</title>
</head>
!Watch out

Type the title exactly as the question gives it, with the same capitals and spaces. A typing error loses the mark.

Attach an external stylesheet

The `<link>` element attaches an external stylesheet. It goes in the head and has no closing tag.

rel="stylesheet" says what the file is. href gives the relative path to the .css file, starting from the HTML file.

index.html is in the cafe folder, and cafe.css is in its styles folder. So the path is styles/cafe.css.

<head>
    <title>Café Retiro | Home</title>
    <link rel="stylesheet" href="styles/cafe.css">
</head>
/* This is the whole of styles/cafe.css so far.
   A .css file contains CSS only: no HTML tags. */
h1 {
    color: #8B4513;
}
?Why?

A relative path still works when the whole folder is copied to another computer or a web server. That is what happens when the examiner opens your work.

!Watch out

Never write href="C:/Users/Lucia/Desktop/cafe/styles/cafe.css". It only works on your own computer. Absolute paths to local files lose the mark.

Meta tags

A `<meta>` tag gives data about the page. It goes in the head and has no closing tag.

charset sets the character set. UTF-8 covers every language, so é, ñ and € show correctly.

description is a short summary. Search engines often show it under the link. keywords lists search words, separated by commas. author names who wrote the page.

viewport tells phones and tablets to use the real screen width, so the page is not shown tiny and zoomed out.

e.g.Example
Without charset UTF-8, "Café" can appear as "Café" in some browsers. Without the viewport tag, a phone shows the page as a shrunken desktop page.
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Café Retiro: coffee, cakes and breakfast next to Retiro Park, Madrid.">
    <meta name="keywords" content="café, coffee, cake, breakfast, Madrid, Retiro">
    <meta name="author" content="Lucía Moreno">
    <title>Café Retiro | Home</title>
    <base target="_blank">
    <link rel="stylesheet" href="styles/cafe.css">
</head>

Default target window: base

The `<base>` element in the head sets the default target for every link on the page.

`<base target="_blank">` makes every link open in a new window or tab. `<base target="_self">` keeps links in the same window, which is the normal behaviour.

A target written on one link overrides the base target for that link only.

<head>
    <base target="_blank">
</head>
<body>
    <a href="menu.html">Menu</a>                 <!-- opens in a new window -->
    <a href="menu.html" target="_self">Menu</a>  <!-- overrides: same window -->
</body>
!Watch out

There is only one base element, and it goes in the head. Put it before the link to the stylesheet.

21.2b HTML body: text, tables and media

Headings and paragraphs

`<h1>` is the main heading. `<h2>` is a subheading. `<h3>` is a heading inside an h2 section.

`<p>` is a paragraph. The browser adds space before and after it.

Use headings in order. Choose the tag for what the text is, not for how big it looks. CSS controls the size.

<h1>Café Retiro</h1>
<h2>Breakfast</h2>
<h3>Served until 12:00</h3>
<p>Fresh coffee, toast with tomato and olive oil, and homemade cakes.</p>
?Why?

Search engines and screen readers use headings to understand the page. A blind visitor can jump from heading to heading.

Ordered and unordered lists

An unordered list `<ul>` shows bullet points. Use it when order does not matter.

An ordered list `<ol>` shows numbers. Use it when order matters, such as steps or a top 3.

Each item goes in `<li>` (list item), inside the ul or ol.

<ul>
    <li>Café con leche</li>
    <li>Tostada con tomate</li>
    <li>Tarta de Santiago</li>
</ul>

<ol>
    <li>Choose a cake.</li>
    <li>Pay at the counter.</li>
    <li>Collect your order.</li>
</ol>
!Watch out

An li must be inside a ul or ol. A list item on its own is invalid HTML.

div and classes

A `<div>` is a box that groups other elements. On its own it changes nothing you can see.

A class is a label you give to elements with the class attribute. CSS can then style everything with that label.

Many elements can share one class. One element can have two classes, separated by a space.

<div class="offer">
    <h2>Today's offer</h2>
    <p>Coffee and a croissant for €3.20.</p>
    <p class="note">Until 11:00 only.</p>
</div>
/* every element with class="offer" */
.offer {
    background-color: #FFF3E0;
    border: 2px dashed #8B4513;
    padding: 10px;
}

.note {
    font-style: italic;
}
?Why?

A class lets you style some paragraphs differently without changing every paragraph.

Tables: table, tr, th, td

`<table>` starts a table. Each row is a `<tr>` (table row).

Inside a row, each cell is a `<td>` (table data) or a `<th>` (table header). Header cells are bold and centred by default.

Build a table row by row, from top to bottom. In each row, write the cells from left to right.

<table>
    <tr>
        <th>Drink</th>
        <th>Price</th>
    </tr>
    <tr>
        <td>Café con leche</td>
        <td>€1.80</td>
    </tr>
    <tr>
        <td>Té verde</td>
        <td>€1.60</td>
    </tr>
</table>
!Watch out

Every row must be closed with `</tr>` before the next `<tr>`. A missing closing tag can shift cells into the wrong row.

Merging cells: colspan and rowspan

colspan makes a cell stretch across several columns. colspan="3" fills 3 columns.

rowspan makes a cell stretch down several rows. rowspan="2" fills 2 rows.

When a cell spans, leave out the cells it covers. A row below a rowspan cell has one cell fewer.

DayOpenClose
Monday to Friday07:3020:00
Saturday09:00 (rowspan="2" covers Saturday and Sunday)21:00
Sunday(covered by the cell above)15:00
e.g.Example
Check by counting columns in each row: Row 1: one th with colspan 3 → 3 columns Row 2: 3 th → 3 Row 3: 3 td → 3 Row 4: Saturday + 09:00 (rowspan 2) + 21:00 → 3 Row 5: Sunday + (09:00 from above) + 15:00 → 3. Only 2 td are written.
<h2 id="hours">Opening hours</h2>
<table>
    <tr>
        <th colspan="3">Opening hours</th>
    </tr>
    <tr>
        <th>Day</th>
        <th>Open</th>
        <th>Close</th>
    </tr>
    <tr>
        <td>Monday to Friday</td>
        <td>07:30</td>
        <td>20:00</td>
    </tr>
    <tr>
        <td>Saturday</td>
        <td rowspan="2">09:00</td>
        <td>21:00</td>
    </tr>
    <tr>
        <td>Sunday</td>
        <td>15:00</td>
    </tr>
</table>
!Watch out

If row 5 also had a cell for 09:00, the row would have 4 columns and the table would stick out on the right.

Table and cell sizes

Set a width or height in pixels (px) for a fixed size, or in percent (%) for a share of the space.

width: 80% on a table makes it 80% of the page width, so it shrinks on a phone. 600px stays the same on every screen.

Use a style attribute in the tag, or a rule in the stylesheet. Older pages use width="80%" attributes. You may see them in source files.

<table style="width:80%">
    <tr>
        <th style="width:200px">Day</th>
        <td style="height:40px">Monday to Friday</td>
    </tr>
</table>
/* the same sizes, set in the stylesheet */
table {
    width: 80%;
}
th {
    width: 200px;
}
td {
    height: 40px;
}
!Watch out

Write the unit with no space: 200px, not 200 px or 200. Without a valid unit, the browser ignores the size.

Images

`<img>` inserts an image. It has no closing tag.

src is the relative path to the image file. alt is the alternative text, read aloud by screen readers and shown if the image cannot load.

width and height set the display size in pixels. Keep the aspect ratio (topic 12), or the image looks stretched.

e.g.Example
tarta.jpg is 600 × 400 pixels. The ratio is 600 ÷ 400 = 1.5. The question asks for a width of 300 pixels. Height = 300 ÷ 1.5 = 200 pixels. The ratio is kept. width="300" height="300" would squash the cake into a square.
<img src="images/tarta.jpg" alt="A slice of tarta de Santiago, an almond cake" width="300" height="200">
?Why?

Alt text makes the page accessible to blind visitors. The exam often asks for it and gives the exact words.

Sound and video

`<audio>` plays sound and `<video>` plays video. Put the file in a `<source>` tag inside them, with its type.

controls shows play, pause and volume buttons. autoplay starts the media when the page loads.

Video takes width and height in pixels. Text inside the element shows only if the browser cannot play the file.

<audio controls>
    <source src="media/jingle.mp3" type="audio/mpeg">
    Your browser cannot play this sound.
</audio>

<video width="480" height="270" controls autoplay muted>
    <source src="media/barista.mp4" type="video/mp4">
    Your browser cannot play this video.
</video>
?Why?

controls, autoplay and muted are true or false attributes. Writing the word switches them on. They need no value.

!Watch out

Most browsers block autoplay with sound. Add muted so autoplay works. Without controls, a visitor cannot pause the media.

Study it

Open the study page and go one step at a time.

The steps for this lesson

Try it

Pages to explore

Check yourself

One question at a time. The reason shows after each answer.

Saved on this device.