Spot the Error
The mistakes that come up again and again in HTML and CSS — what each one looks like, what it does, and a method for finding them.
Why errors hide
The three languages fail in three different ways:
| When something is wrong | |
|---|---|
| HTML | the browser guesses. It repairs what it can and shows the page anyway — often looking almost right |
| CSS | the browser skips. The broken declaration, or the whole rule, is ignored — without a message |
| JavaScript | the code stops. A red message appears in the Console |
So HTML and CSS errors do not announce themselves. You have to see them — which is exactly what the exam asks of you.
Two tools see them for you: the W3C validator for HTML, and DevTools → Styles, which strikes through every CSS declaration it could not use.
A method: two checklists
Go through the code line by line, once for each question. It is slower than reading it once — and it finds what reading once misses.
HTML
- Does every tag that opens also close — in the reverse order it opened?
- Is every quote closed?
href="about.html"— two quotes, always. - Does every
<img>have analt? - Is everything visible inside
<body>, and only information about the page inside<head>? - Is every
<li>inside a<ul>or an<ol>? - Is every path written with
/, in lower case, without spaces, and relative to the site? - Is every
idused only once, and does every<label for>match anid? - Are the element names spelled right?
<header>, not<heder>.
CSS
- Does every
{have its}? - Does every declaration end with
;? - Is there a colon between property and value — not
=, not nothing? - Is the property name real?
color, nevercolour.background-color, neverbackground-colour. - Does every length have a unit, with no space before it?
16px— not16, not16 px. - Does the selector match the HTML?
.for a class,#for an id — same spelling, same capitals. - Are the comments
/* … */?//and<!-- -->are not CSS. - Is the stylesheet linked, with the right file name?
HTML errors
| You see | What is wrong | What happens |
|---|---|---|
<h2>Our places and no </h2> | the heading is never closed | what follows becomes part of the heading — big and bold |
<p>Open <strong>daily</p></strong> | closed in the wrong order | the browser repairs it — but it is invalid, and the repair is a guess |
<a href="menu.html>Menu</a> | a quote is never closed | the address swallows the text after it: the link vanishes, and the next one breaks |
<img src="hero.webp"> | no alt | invisible to anyone who cannot see it; the validator reports it |
<img src="hero.webp" alt="…"></img> | <img> has no closing tag | invalid: </img> is a stray end tag |
<li> directly inside <footer> | a list item outside a list | invalid: <li> belongs inside <ul> or <ol> |
<h1> inside <head> | visible content in the head | the browser moves it into the body — but it is invalid |
a <head> with no <title> | the title is missing | invalid; the tab shows the file name instead |
two elements with id="contact" | an id used twice | invalid: an id is unique on its page |
<label for="email"> and <input id="mail"> | for and id do not match | clicking the label does nothing; a screen reader cannot name the field |
<heder> | a misspelled element | the browser does not know it: no meaning, no default style |
nav.html starting with <!DOCTYPE html> | a fragment written as a whole page | an <html> inside an <html> — the browser throws most of it away |
Not every missing end tag is an error. HTML lets you leave out
</li>before the next<li>, and</p>before a new block such as another<p>or a heading — the validator accepts both. Close them anyway: it is clearer, and leaving them out is how the real errors hide.
Valid — but wrong
These pass the validator. They are still mistakes, because they break what HTML is for: saying what things are.
| You see | Why it is wrong |
|---|---|
an <h1>, then an <h4> | headings chosen by size: the outline skips levels. Want smaller text? That is CSS |
two <h1> on one page | one page, one main heading |
<b>Warning</b> | bold pixels with no meaning — <strong> says it matters |
<div class="nav"> | a navigation that does not say so: use <nav> |
<a href="work.html">click here</a> | link text is read out of context. Say where it goes |
alt="image" or alt="IMG_2041.jpg" | alt text that describes nothing |
<input placeholder="Email"> and no label | the placeholder vanishes as soon as you type |
a <table> holding the page layout | tables are for data, never for layout |
href="https://mei.example.com/about.html" to your own page | an absolute address to your own page breaks when the site moves |
CSS errors
| You see | What is wrong | What happens |
|---|---|---|
color: #333 with no ; — then font-size: 16px; | a missing semicolon | both lines are lost: the browser reads #333 font-size: 16px as one value for color |
a rule with no closing } | a missing brace | the rules after it stop working |
colour: red; | not a property — CSS spells it color | ignored |
text-color: red; · font-colour: red; | not properties either | ignored |
font-size: 16; | a length with no unit | ignored. Only 0 may stand alone |
font-size: 16 px; | a space between the number and the unit | ignored |
color = red; · color red; | no colon | ignored |
.Quote for class="quote" | class names are case-sensitive | matches nothing |
#quote for class="quote" | # is for an id, . for a class | matches nothing |
quote { … } for class="quote" | the dot is missing | looks for a <quote> element — there is none |
// the header | not a CSS comment | the rule below it breaks. Write /* the header */ |
href="styles.css" for a file called style.css | the file name does not match | no styling at all; DevTools → Network shows a 404 |
Two notes that stop you finding errors that are not there:
- The last semicolon in a rule is optional. That is why a missing one hides: nothing breaks until someone adds a line below it.
- Some properties take plain numbers, and that is correct:
line-height: 1.5,font-weight: 800.
Works — but not how you think
| You see | What actually happens |
|---|---|
color: red; to make a box red | color is the text colour. The box is background-color |
footer { … } to style the site footer | it also styles every <footer> inside an <article> — every quote card. Use #site-footer |
style="…" on twenty elements | twenty places to change. One class, one rule |
Paths and file names
Your site will live on a Linux server, where Photo.jpg and photo.jpg are two different files. Windows and macOS treat them as the same file — which is why a site can work on your laptop and break online.
| Path | Verdict |
|---|---|
images/hero.webp | ✓ relative, lower case, forward slash |
Images/Hero.webp — but the folder is images, the file hero.webp | ✗ capitals: works on your laptop, 404 on the server |
images\hero.webp | ✗ a backslash is a Windows habit. Addresses use /, and the validator rejects \ |
C:\Users\mei\Desktop\my-site\images\hero.webp | ✗ a path on your own disk. Nobody else has your C: drive |
www.example.com/logo.png | ✗ no https://, so the browser looks for a folder called www.example.com inside your site |
https://example.com/logo.png | ✓ a valid absolute address — but on someone else's server |
images/my photo.webp | ✗ a space: it becomes %20, and the validator rejects it |
| File name | Verdict |
|---|---|
about.html | ✓ |
index.html | ✓ — and special: the front page of its folder |
beach-photo-2024.webp | ✓ lower case, hyphens |
About Me.html | ✗ a capital and a space |
contact_form.html | works — but the rule is hyphens |
café-menu.html | ✗ é is not in a–z; in an address it turns into caf%C3%A9-menu.html |
关于我们.html | ✗ the same, for every character. Write the page in Chinese; name the file in a–z |
photo.JPG | ✗ capitals in the extension count too |
Practice
The code is shown without colours, as it will be on paper. Colours would give some errors away.
1 · Five errors in HTML
Give the line number, say what is wrong, and say what would fix it.
1 <!DOCTYPE html>
2 <html lang="en">
3 <head>
4 <meta charset="UTF-8">
5 <meta name="viewport" content="width=device-width, initial-scale=1.0">
6 <link rel="stylesheet" href="style.css">
7 </head>
8 <body>
9 <header>
10 <h1>Coconut Radio
11 </header>
12 <main>
13 <section id="gigs">
14 <h2>Next gigs</h2>
15 <img src="images/stage.webp" alt="The band on stage at a beach bar in Haikou"></img>
16 </section>
17 <section id="gigs">
18 <h2>Join the mailing list</h2>
19 <label for="email">Your email</label>
20 <input id="mail" type="email">
21 </section>
22 </main>
23 </body>
24 </html>
Show the answers
- Lines 3–7: there is no
<title>. Every page needs one — without it, the tab shows the file name. Add<title>Coconut Radio</title>to the head. - Line 10: the
<h1>is never closed. Here the browser closes it at</header>, so it happens to look right — but it is invalid, and one line later it would not look right. Add</h1>. - Line 15:
</img>.<img>has no closing tag. Delete it. - Line 17:
id="gigs"is already used on line 13. An id is unique on its page. Give this section its own, such asid="mailing-list". - Lines 19–20:
for="email", butid="mail". They must match, or the label is not connected to the field.
2 · Five errors in CSS
The HTML this styles uses <article class="quote"> for each quote.
1 body {
2 font-family: system-ui, sans-serif;
3 line-height: 1.5;
4 background-colour: #fbfaf7;
5 }
6
7 main {
8 max-width: 48rem
9 margin: 0 auto;
10 }
11
12 #quote {
13 padding: 1.5rem;
14 border-left: 4px solid #c2410c;
15 }
16
17 .quote cite {
18 color: #6b7280;
19 font-size: 14;
20 }
21
22 nav a {
23 text-decoration: none;
24
25 nav .logo {
26 font-weight: 800;
27 }
Show the answers
- Line 4:
background-colour. CSS spells itbackground-color. Ignored. - Line 8: no semicolon. The browser reads
48rem margin: 0 autoas one value formax-width, so both lines are lost. Add;. - Line 12:
#quote. The HTML usesclass="quote", so the selector is.quote. As it is, it matches nothing. - Line 19:
14has no unit. Write14px, or0.875rem. Ignored as it is. - Line 24: the
nav arule is never closed. Thenav .logorule ends up inside it and stops working. Add}after line 23.
Not errors: line-height: 1.5 and font-weight: 800 take plain numbers. That is correct.