How HTML structures a web page: doctypes, elements, tags and attributes
Every web page you have ever opened began as a plain text file of HTML.
HTML (HyperText Markup Language) does not make anything look pretty and does not make anything move: it says what each piece of content is (a heading, a paragraph, a link, a picture, a form) so that a browser knows how to show it and a screen reader knows how to read it.
This is AS Level content for Unit 2, the WIT12 practical paper, where you open real HTML files in a text editor, fix or extend them and save them, so everything here is something you will type, not just describe.
Your syllabus expects you to understand how HTML is used to structure web pages: a. doctypes; b. elements; c. tags; d. attributes.
(Unit 2, WIT12/01, for the whole of Topic 7)
- A 3-hour practical exam at a computer with a plain text editor and a browser, no internet and no software that completes or checks code for you. HTML is about 15% of the marks directly, but every CSS and JavaScript mark sits on top of HTML you have to get right.
- Section A, Question 1 (8 or 9 marks) is the HTML question. It opens with two 1-mark recall parts (Give, State or Name), and it always contains a debugging item: a figure shows how a page should look, the starter file has exactly two errors, and you open it in a browser, find them, correct them and save it [2]. It may also hold an Explain [2], a Describe [2], a Complete the table [2] or an Add [2] item (an
idplus a link to it).
- Section B (49 marks) is set on one organisation: Question 4 asks you to Develop a web page from a design [20], and its link and semantic-element marks are HTML marks; Question 6 [9] can be about form design (Analyse and recommend).
- Commands for HTML: Give, State or Name [1], Describe [2], Explain [2], Complete a table [2], Amend [2 to 4], Add [2], and the 9-mark Analyse and recommend or Assess. There is no multiple choice.
The idea: markup wraps content in labels
Ravenscar Climbing Wall wants a page listing its routes.
The words "Climbing routes" are just text until you wrap them: <h1>Climbing routes</h1> tells the browser "this is the main heading", so it is shown large and bold, search engines treat it as the page's topic, and a screen reader announces it as heading level 1.
HTML is called a markup language because it marks up existing content with labels; it is not a programming language, because it has no variables, decisions or loops.
You need to know four words for the parts you use to build that structure.
Doctype. The very first line of an HTML5 file is <!DOCTYPE html>.
It is not an element and has no closing tag.
It is an instruction to the browser that says which version of HTML the page is written in, and so how to interpret it.
With it, the browser uses standards mode and follows the current HTML and CSS rules exactly.
Without it, browsers fall back to quirks mode, which copies the habits of very old browsers so that pages from the 1990s still display; layout, box sizes and some CSS then behave differently from what you wrote.
So the doctype is there to make the page display the same, correctly, in every modern browser.
Older HTML versions had long doctypes naming a DTD file; HTML5 shortened it to the one line, and it is not case-sensitive, though <!DOCTYPE html> is the usual way to write it.
Element. An element is one complete piece of the page's structure: usually an opening tag, some content and a closing tag.
<p>Open until 10pm</p> is a paragraph element.
Elements nest inside each other like boxes inside boxes: a list element contains list-item elements; the body element contains everything visible.
Some elements have no content at all and so no closing tag; these are void (empty, or "self-closing") elements such as <img>, <br>, <hr>, <input>, <meta> and <link>.
Tag. A tag is the label in angle brackets that starts or ends an element.
The opening tag is <p>; the closing tag repeats the name after a forward slash, </p>.
Tag names are what the browser reads to decide what kind of element it is building.
"Element" and "tag" are often used loosely as if they meant the same thing; in an answer, keep them apart: the tag is the marker, the element is the whole thing from opening tag to closing tag.
Attribute. An attribute adds information to an element and is written inside its opening tag as a name, an equals sign and a value in double quotes: <a href="routes.html">.
Here href is the attribute name and routes.html its value, which tells the link where to go.
An element can have several attributes, separated by spaces, in any order: <img src="wall.jpg" alt="The bouldering cave" width="400">.
Attributes never go in a closing tag.
The figure takes one link apart.
Read it from the outside in: the whole bracket is the element; the box on the left is the opening tag, carrying the tag name a and one attribute; the middle box is the content the user sees and clicks; the box on the right is the closing tag.
In the file it is written <a href="routes.html">Climbing routes</a>.
- HTML (HyperText Markup Language): the markup language that describes the structure and meaning of the content of a web page, using elements written with tags.
- Doctype declaration: the first line of an HTML document,
<!DOCTYPE html>in HTML5, which tells the browser which version of HTML the page uses so that it renders in standards mode.
- Element: one component of a page, normally an opening tag, its content and a closing tag, such as a heading, paragraph, list or image.
- Tag: the name of an element in angle brackets,
<p>, marking where an element starts; the closing tag,</p>, marks where it ends.
- Attribute: extra information about an element, written in its opening tag as a name and a value in double quotes, such as
href="routes.html".
- Void element: an element with no content and no closing tag, such as
img,br,hr,input,metaandlink.
How a browser turns the file into a page
When you open a page, the browser reads the file from the top.
The doctype sets the mode.
Then it reads tags one by one and builds a tree of elements in memory: html at the root, head and body under it, and so on down to each paragraph and link.
That tree (the Document Object Model, which Topic 9 uses to let JavaScript change the page) is what is drawn on screen.
This is why structure matters: a missing closing tag does not stop the page loading, but the browser has to guess where the element ends, and its guess often swallows the content after it.
In the debugging items, that guess is exactly what you see go wrong.
Every HTML5 page has the same skeleton:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Ravenscar Climbing Wall: routes</title>
</head>
<body>
<h1>Climbing routes</h1>
<p>New routes are set every Friday.</p>
</body>
</html>
<!DOCTYPE html>: the doctype, always line 1.
html: the root element; everything else sits inside it. Itslangattribute declares the page's language (the next section).
head: information about the page, not shown in the page area: the character set, the title shown on the browser tab, links to style sheets and scripts.
body: everything the user sees in the window.
CSS rules (Topic 8) pick elements out by their tag name, class or id, so the structure you write decides what can be styled.
JavaScript (Topic 9) reaches elements through the tree the browser builds from your tags.
A page with tidy, correctly closed elements is the foundation both of them need.
Ravenscar's booking page contains this line:
<img src="images/cave.jpg" alt="Bouldering cave with soft matting" width="320">
Name the element, its tag, each attribute and its value, and say whether it needs a closing tag.
1. The tag name is img, so this is an image element.
2. It has three attributes: src with the value images/cave.jpg (where the picture file is), alt with the value Bouldering cave with soft matting (text shown or read aloud if the picture cannot be seen) and width with the value 320 (pixels).
3. img is a void element: it has no content, so there is no closing tag and nothing like </img>.
Answer: an image element, opened by the img tag, with attributes src, alt and width; no closing tag.
(Give [1] shape)
A student's page starts directly with <html> and has no doctype.
Give one reason why a doctype should be declared.
Answer: so that the browser knows which version of HTML the page uses and displays it in standards mode, the same way in different browsers (1).
A weaker answer: "It declares the document type."
This only repeats the words of the question, so it scores nothing: the mark needs what the doctype makes the browser do.
Write a complete, minimal HTML5 page for Ravenscar's opening times: browser tab text "Ravenscar opening times", a main heading "Opening times" and one paragraph "Monday to Friday, 12:00 to 22:00".
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Ravenscar opening times</title>
</head>
<body>
<h1>Opening times</h1>
<p>Monday to Friday, 12:00 to 22:00</p>
</body>
</html>
1. Line 1 is the doctype; nothing, not even a blank comment, should come before it.
2. The title goes in the head, so it appears on the tab, not in the page.
3. The heading and paragraph go in the body, each closed with its own closing tag.
Outcome: the tab reads "Ravenscar opening times"; the window shows a large bold heading "Opening times" with the hours underneath in normal text.
(debugging, Amend [2] shape)
A page should show a heading "Bouldering" and, below it in normal text, "No ropes needed".
The browser instead shows both lines large and bold.
The code is:
12 <h2>Bouldering
13 <p>No ropes needed</p>
1. Compare the render with what was intended: the paragraph has taken the heading's style, so the heading must still be open when the paragraph starts.
2. Line 12 has an opening <h2> but no </h2>.
Answer: add </h2> after "Bouldering" on line 12.
The heading then ends there and the paragraph is drawn as ordinary text.
In a debugging item, open the starter file in the browser first and compare it with the figure line by line before you look at the code: the first place where the render differs from the figure is where to start reading.
Then check that every opening tag has its closing tag and that each element is inside the right parent.
Exactly two errors are planted, one mark each, so stop when the page matches the figure.
- Saying the doctype "declares the document type". That repeats the question. Say what it does: tells the browser the HTML version so the page is interpreted and displayed correctly (standards mode).
- Calling the doctype an element or a tag. It is a declaration, it has no closing tag, and it must come before
<html>.
- Mixing up "tag" and "element".
<p>is a tag;<p>Open late</p>is an element. Examiners expect the right word.
- Putting attributes in the closing tag or leaving out the quotes.
</a href="x">is wrong; attributes belong in the opening tag, value in double quotes.
- Writing a closing tag for a void element. There is no
</img>or</br>; adding one is an error a validator reports.
(every file-based HTML item)
- Open the starter file named in the question in a plain text editor, make the change, and save it under the given name with
FINISHEDadded, for exampleQ01dFINISHED.html.
- Save it in the folder the original came from, so relative paths to images, style sheets and other pages still work. Never point a link or
srcat your desktop or a drive letter.
- Open the saved file in the browser and check every requirement bullet: each one is a mark only if it shows when the examiner opens your file.
- At the end, zip the whole Questions folder with its structure unchanged. The files are the evidence: there are no screenshots in this paper.
Check your understanding
1. State what the doctype declaration is for at the start of an HTML document. (1) Total [1]
2. Give the name of the part of <a href="prices.html">Prices</a> that tells the browser which page to open. (1)
Total [1]
3. Explain one difference between a tag and an element. (2) Total [2]
4. A student says: "HTML is a programming language, because the browser follows the instructions in it." Explain why this is not correct. (2) Total [2]
5. A page should show a heading "Route grades" and, under it, the paragraph "Grades run from 3 to 8a". Lines 9 and 10 of grades.html are:
9 <h2>Route grades</h3>
10 <p>Grades run from 3 to 8a<p>
The page contains two errors.
Open the file in a browser, then Amend the code in your editor to correct both errors.
Save it as gradesFINISHED.html (2)
Total [2]
6. Describe what a void element is. (2) Total [2]
Answers
1. It tells the browser which version of HTML the page is written in, so the browser interprets and displays it correctly (in standards mode) (1). Not credited: "it declares the type of document" (repeats the question).
2. The href attribute (accept: the attribute, or its value prices.html) (1).
3. A tag is the marker in angle brackets that starts or ends an element, such as <h1> (1), whereas an element is the whole component: the opening tag, its content and its closing tag together (1).
4. HTML only describes the structure and meaning of content, such as which text is a heading or a link (1), whereas a programming language has logic such as variables, selection and loops, which HTML does not have, so it is a markup language (1).
5. C1: the closing tag on line 9 changed to </h2> so it matches the opening <h2> (1). C2: the second <p> on line 10 changed to the closing tag </p> (1). Saved as gradesFINISHED.html in the same folder.
6. An element that has no content between tags (1), so it is written as a single tag with no closing tag, such as <img> or <br> (1).