HTML Exercises
Time to practise! Each task below has a starter playground. Edit the code, press ▶ Run (or Ctrl+Enter) to see your result, and only open the solution once you have had a real try. There is usually more than one correct answer — if yours renders correctly and uses sensible elements, it counts.
| # | Topic |
|---|---|
| 1 | Headings and paragraphs |
| 2 | Links |
| 3 | Images |
| 4 | Lists |
| 5 | Tables |
| 6 | Forms |
| 7 | Semantic layout |
| 8 | Entities and formatting |
Exercise 1 — Headings and paragraphs
Turn the plain text into a page with a main heading "My Hobbies", a second-level heading "Reading", and a paragraph under it. Make the word favourite bold (with <strong>).
<!DOCTYPE html>
<html>
<body>
My Hobbies
Reading
Reading is my favourite way to relax in the evening.
</body>
</html>Show solution
<!DOCTYPE html>
<html>
<body>
<h1>My Hobbies</h1>
<h2>Reading</h2>
<p>Reading is my <strong>favourite</strong> way to relax in the evening.</p>
</body>
</html>Exercise 2 — Links
Make "Jump to contact" a link to the element with id="contact" on the same page, and make "Example site" a link to https://example.com that opens in a new tab.
<!DOCTYPE html>
<html>
<body>
<p>Jump to contact</p>
<p>Example site</p>
<div style="height:600px"></div>
<h2 id="contact">Contact</h2>
<p>Email me any time.</p>
</body>
</html>Show solution
<p><a href="#contact">Jump to contact</a></p>
<p><a href="https://example.com" target="_blank" rel="noopener">Example site</a></p>Exercise 3 — Images
Add an image of a sun using the src already prepared in the comment (an inline SVG data URI). Give it a useful alt text and a width of 100 pixels.
<!DOCTYPE html>
<html>
<body>
<!-- src: data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Ccircle cx='50' cy='50' r='30' fill='orange'/%3E%3C/svg%3E -->
<h2>Today's weather</h2>
<p>Sunny all day.</p>
</body>
</html>Show solution
<img src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Ccircle cx='50' cy='50' r='30' fill='orange'/%3E%3C/svg%3E"
alt="A bright orange sun" width="100">Exercise 4 — Lists
Create an ordered list of three steps for making tea, and inside the second step add a nested unordered list with two items: "Green tea" and "Black tea".
<!DOCTYPE html>
<html>
<body>
<h2>Making tea</h2>
<!-- Boil water / Choose your tea (Green tea, Black tea) / Pour and wait 3 minutes -->
</body>
</html>Show solution
<h2>Making tea</h2>
<ol>
<li>Boil water</li>
<li>Choose your tea
<ul>
<li>Green tea</li>
<li>Black tea</li>
</ul>
</li>
<li>Pour and wait 3 minutes</li>
</ol>Exercise 5 — Tables
Build a table with a caption "Class timetable", a header row (Day, Subject) and two data rows: Monday / Maths and Tuesday / Science. The CSS is already done for you.
<!DOCTYPE html>
<html>
<head>
<style>
table { border-collapse: collapse; }
th, td { border: 1px solid #999; padding: 6px 12px; }
th { background: #eee; }
</style>
</head>
<body>
<!-- your table here -->
</body>
</html>Show solution
<table>
<caption>Class timetable</caption>
<thead>
<tr><th>Day</th><th>Subject</th></tr>
</thead>
<tbody>
<tr><td>Monday</td><td>Maths</td></tr>
<tr><td>Tuesday</td><td>Science</td></tr>
</tbody>
</table>Exercise 6 — A sign-up form
Make a form with: a labelled email field that is required, a labelled password field with at least 8 characters, a checkbox "I agree to the rules" that is required, and a submit button. Try submitting it empty to see the browser's validation.
<!DOCTYPE html>
<html>
<body>
<form>
<!-- fields here -->
</form>
</body>
</html>Show solution
<form>
<p>
<label for="email">Email</label>
<input type="email" id="email" name="email" required>
</p>
<p>
<label for="pw">Password</label>
<input type="password" id="pw" name="password" minlength="8" required>
</p>
<p>
<label><input type="checkbox" name="agree" required> I agree to the rules</label>
</p>
<button type="submit">Sign up</button>
</form>Exercise 7 — Semantic layout
The page below uses only <div>s. Replace them with the right semantic elements: <header>, <nav>, <main>, <article>, <aside> and <footer>.
<!DOCTYPE html>
<html>
<body>
<div class="top"><h1>Tech Blog</h1></div>
<div class="menu"><a href="#">Home</a> | <a href="#">Posts</a></div>
<div class="content">
<div class="post"><h2>Why HTML matters</h2><p>It is the skeleton of the web.</p></div>
<div class="side">Related: CSS basics</div>
</div>
<div class="bottom">© 2026 Tech Blog</div>
</body>
</html>Show solution
<header><h1>Tech Blog</h1></header>
<nav><a href="#">Home</a> | <a href="#">Posts</a></nav>
<main>
<article><h2>Why HTML matters</h2><p>It is the skeleton of the web.</p></article>
<aside>Related: CSS basics</aside>
</main>
<footer>© 2026 Tech Blog</footer>Exercise 8 — Entities and formatting
Display this sentence exactly, including the angle brackets: Use <p> for paragraphs & <br> for line breaks. Then add a line showing the chemical formula H₂O using <sub>, and the text "x squared" as x² using <sup>.
<!DOCTYPE html>
<html>
<body>
<p><!-- sentence here --></p>
<p><!-- H2O here --></p>
<p><!-- x squared here --></p>
</body>
</html>Show solution
<p>Use <p> for paragraphs & <br> for line breaks.</p>
<p>H<sub>2</sub>O</p>
<p>x<sup>2</sup></p>Test yourself
Which attribute makes a link open in a new tab?
new="tab"target="_blank"rel="new"href="_blank"
How do you display a literal < character in HTML text?
\<<<<&less;
Which element should wrap the site's main navigation links?
<menu><nav><links><header>only