Learn HTML
This is the main article.
All HTML exercises in one list: headings, text formatting, links, images, lists, tables, forms, a navigation menu and a page layout with semantic elements.
Description: Write an HTML program that displays “Hello, World!” on a web page.
Hint:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Hello World</title>
</head>
<body>
<h1>Hello, World!</h1>
</body>
</html>
Output in the browser:
<!DOCTYPE html> tells the browser that this is an HTML5 page.<title> is shown on the browser tab.<h1> inside the body is the visible heading.Learn the structure in HTML Page Structure.
Description: Create a web page that prints the values 1 to 5. Each value should be on a new line.
Hint:
<p> tag for each value, or the <br> tag for a line break.<!DOCTYPE html>
<html lang="en">
<head>
<title>Numbers</title>
</head>
<body>
<p>1</p>
<p>2</p>
<p>3</p>
<p>4</p>
<p>5</p>
</body>
</html>
Output in the browser:
1
2
3
4
5
<p> tag is a paragraph, and the browser puts each paragraph on a new line.1<br>2<br>3<br>4<br>5 inside one paragraph. The <br> tag gives a line break.<ol>. See HTML Lists.Description: Create a web page that prints the name of your city in red colour.
Hint:
style attribute with the CSS color property.<font color="red"> tag is not valid in HTML5.<!DOCTYPE html>
<html lang="en">
<head>
<title>My City</title>
</head>
<body>
<h1 style="color: red;">Delhi</h1>
</body>
</html>
Output in the browser:
style attribute holds CSS for this element only.color: red; changes the text colour to red. You can also use a hex code like #ff0000.Learn more in HTML Styles.
Description: Create a web page with a paragraph of 4 sentences. Each sentence should have a different font and colour.
Hint:
<p> tag.<span> and use font-family and color in the style attribute.<!DOCTYPE html>
<html lang="en">
<head>
<title>Fonts and colours</title>
</head>
<body>
<p>
<span style="font-family: Arial; color: red;">This sentence is in Arial and red.</span>
<span style="font-family: 'Times New Roman'; color: green;">This one is in Times New Roman and green.</span>
<span style="font-family: Verdana; color: blue;">This one is in Verdana and blue.</span>
<span style="font-family: 'Courier New'; color: purple;">The last one is in Courier New and purple.</span>
</p>
</body>
</html>
Output in the browser:
This sentence is in Arial and red. This one is in Times New Roman and green. This one is in Verdana and blue. The last one is in Courier New and purple.
<span> is an inline tag, so all sentences stay in the same paragraph.font-family and color.<font> tag for this. It is removed from HTML5, so we use CSS.See HTML Div and Span.
Description: Create a web page with your name as the heading, a short paragraph about you, and a list of your hobbies.
Hint:
<h1> for the name, <p> for the paragraph and <ul> for the hobbies.<!DOCTYPE html>
<html lang="en">
<head>
<title>About Me</title>
</head>
<body>
<h1>Robin Kumar</h1>
<p>I am a student and I am learning web development.</p>
<h2>My hobbies</h2>
<ul>
<li>Reading</li>
<li>Cricket</li>
<li>Music</li>
</ul>
</body>
</html>
Output in the browser:
I am a student and I am learning web development.
h1 is the main heading and the h2 is a sub heading.<li> inside the <ul>.Related: HTML Headings and HTML Lists.
Description: Create a web page that shows the headings from h1 to h6.
Hint:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Headings</title>
</head>
<body>
<h1>Heading 1</h1>
<h2>Heading 2</h2>
<h3>Heading 3</h3>
<h4>Heading 4</h4>
<h5>Heading 5</h5>
<h6>Heading 6</h6>
</body>
</html>
Output in the browser:
h1 is the biggest and most important heading, and h6 is the smallest.h1 on a real page.Read HTML Headings.
Description: Create a web page that shows important text, emphasised text, highlighted text, the formula of water (H2O) and the square of a number (5 squared).
Hint:
strong, em, mark, sub and sup tags.<!DOCTYPE html>
<html lang="en">
<head>
<title>Text Formatting</title>
</head>
<body>
<p>This is <strong>important</strong> text.</p>
<p>This is <em>emphasised</em> text.</p>
<p>This is <mark>highlighted</mark> text.</p>
<p>The formula of water is H<sub>2</sub>O.</p>
<p>5<sup>2</sup> is 25.</p>
<p>Old price <del>$100</del>, new price <ins>$80</ins>.</p>
</body>
</html>
Output in the browser:
This is important text.
This is emphasised text.
This is highlighted text.
The formula of water is H2O.
52 is 25.
Old price $100, new price $80.
strong shows bold and em shows italic text.sub lowers the text and sup raises it.del draws a line through the text and ins underlines it.Read HTML Formatting.
Description: Create a web page with a link that opens a website in a new tab, a link to another page of your site, and a link to send an email.
Hint:
<a> tag with href.target="_blank" for a new tab and mailto: for an email link.<!DOCTYPE html>
<html lang="en">
<head>
<title>Links</title>
</head>
<body>
<p><a href="https://www.example.com" target="_blank" rel="noopener">Visit Example (new tab)</a></p>
<p><a href="about.html">About us</a></p>
<p><a href="mailto:info@example.com">Send an email</a></p>
</body>
</html>
Output in the browser:
target="_blank" opens the link in a new tab, and rel="noopener" keeps it safe.about.html is a relative link to a file in the same folder.mailto: opens the email app of the visitor.Read HTML Links.
Description: Create a web page that shows an image of size 120 x 80 pixels, and another copy of the image that opens a website when clicked.
Hint:
<img> tag with src, alt, width and height.<a> tag to make it a link.<!DOCTYPE html>
<html lang="en">
<head>
<title>Image</title>
</head>
<body>
<img src="orange.png" alt="Orange sample picture" width="120" height="80">
<a href="https://www.example.com">
<img src="orange.png" alt="Go to Example" width="120" height="80">
</a>
</body>
</html>
Output in the browser:
How it works
src is the path of the picture. Keep the file in the same folder as the HTML file, or write the right path.alt is shown if the picture cannot load.<a> the image becomes clickable.Read HTML Images.
Description: Create a web page with a bullet list of 5 fruits.
Hint:
<ul> for the list and one <li> for each fruit.<!DOCTYPE html>
<html lang="en">
<head>
<title>Fruits</title>
</head>
<body>
<h2>My favourite fruits</h2>
<ul>
<li>Apple</li>
<li>Banana</li>
<li>Mango</li>
<li>Orange</li>
<li>Grapes</li>
</ul>
</body>
</html>
Output in the browser:
ul means unordered list. The browser shows bullet points.li tag.style="list-style-type: square;" to the ul to change the bullet type.Read HTML Lists.
Description: Create a numbered list of three steps that starts from number 5. Then create a nested list of Fruits and Vegetables with two sub items each.
Hint:
<ol start="5"> to start from 5.<ul> inside an <li>.<!DOCTYPE html>
<html lang="en">
<head>
<title>Lists</title>
</head>
<body>
<ol start="5">
<li>Open the editor</li>
<li>Write the code</li>
<li>Save the file</li>
</ol>
<ul>
<li>Fruits
<ul>
<li>Apple</li>
<li>Mango</li>
</ul>
</li>
<li>Vegetables
<ul>
<li>Potato</li>
<li>Tomato</li>
</ul>
</li>
</ul>
</body>
</html>
Output in the browser:
start attribute sets the first number of an ordered list.<ul> is inside the <li> of its parent item, so it shows as a sub list.Read HTML Lists.
Description: Create a table that shows the name and marks of three students, with a header row and borders.
Hint:
th for the header cells and td for the data cells.<!DOCTYPE html>
<html lang="en">
<head>
<title>Marks</title>
<style>
table { border-collapse: collapse; }
th, td { border: 1px solid #999; padding: 8px; }
</style>
</head>
<body>
<table>
<tr><th>Name</th><th>Marks</th></tr>
<tr><td>Robin</td><td>85</td></tr>
<tr><td>Maria</td><td>92</td></tr>
<tr><td>John</td><td>78</td></tr>
</table>
</body>
</html>
Output in the browser:
| Name | Marks |
|---|---|
| Robin | 85 |
| Maria | 92 |
| John | 78 |
tr is a row. The first row has header cells (th), which are bold.border-collapse: collapse joins the borders of neighbour cells into one line.Read HTML Tables.
Description: Create a small timetable with a heading cell that covers two columns, and one subject name that covers two rows.
Hint:
colspan merges cells in a row, and rowspan merges cells in a column.<table border="1">
<tr>
<th colspan="2">Monday Timetable</th>
</tr>
<tr>
<td rowspan="2">Morning</td>
<td>Maths</td>
</tr>
<tr>
<td>Science</td>
</tr>
<tr>
<td>Afternoon</td>
<td>Sports</td>
</tr>
</table>
Output in the browser:
| Monday Timetable | |
|---|---|
| Morning | Maths |
| Science | |
| Afternoon | Sports |
colspan="2", so it covers both columns.rowspan="2", so it covers two rows. Because of this, the “Science” row has only one cell.border="1" attribute is used here only to keep the code short. In real pages use CSS borders.Read Rowspan and Colspan.
Description: Create a registration form that takes name, email, password, gender, hobbies and country, and has a Register button.
Hint:
form tag with method="post".label to its field with for and id.name.<form action="register.php" method="post">
<p><label for="name">Name:</label>
<input type="text" id="name" name="name" required></p>
<p><label for="email">Email:</label>
<input type="email" id="email" name="email" required></p>
<p><label for="pass">Password:</label>
<input type="password" id="pass" name="password" required></p>
<p>Gender:
<input type="radio" id="m" name="gender" value="male"><label for="m">Male</label>
<input type="radio" id="f" name="gender" value="female"><label for="f">Female</label></p>
<p>Hobbies:
<input type="checkbox" id="h1" name="hobby" value="reading"><label for="h1">Reading</label>
<input type="checkbox" id="h2" name="hobby" value="music"><label for="h2">Music</label></p>
<p><label for="country">Country:</label>
<select id="country" name="country">
<option value="india">India</option>
<option value="usa">USA</option>
</select></p>
<button type="submit">Register</button>
</form>
Output in the browser:
required attribute stops the form from being sent when the field is empty.type="email" checks the email format, and type="password" hides the typed text.register.php with the POST method. That file must be made with a server language like PHP.Read HTML Forms and HTML Input Types.
Description: Create a contact form with name, email, subject and message fields, and a Send button.
Hint:
textarea for the long message.required.<form action="contact.php" method="post">
<p><label for="cname">Name:</label><br>
<input type="text" id="cname" name="name" required></p>
<p><label for="cemail">Email:</label><br>
<input type="email" id="cemail" name="email" required></p>
<p><label for="subject">Subject:</label><br>
<input type="text" id="subject" name="subject"></p>
<p><label for="message">Message:</label><br>
<textarea id="message" name="message" rows="5" cols="40" required></textarea></p>
<button type="submit">Send</button>
</form>
Output in the browser:
<br> puts the field below its label.rows and cols set the size of the textarea.contact.php reads the values and sends the email. A form alone cannot send an email.Also see our HTML contact form template.
Description: Create a navigation menu with the links Home, About, Services and Contact, shown in one line.
Hint:
ul, li and a inside a nav tag.<nav>
<ul class="menu">
<li><a href="index.html">Home</a></li>
<li><a href="about.html">About</a></li>
<li><a href="services.html">Services</a></li>
<li><a href="contact.html">Contact</a></li>
</ul>
</nav>
<style>
.menu { list-style: none; padding: 0; }
.menu li { display: inline-block; margin-right: 15px; }
</style>
Output in the browser:
nav tag tells that this block has navigation links.list-style: none removes the bullets, and display: inline-block puts the items in a row.Read HTML Semantic Elements.
Description: Create a web page layout with a header, a navigation bar, a main area with an article and a sidebar, and a footer.
Hint:
header, nav, main, article, aside and footer.<!DOCTYPE html>
<html lang="en">
<head>
<title>My Blog</title>
</head>
<body>
<header>
<h1>My Blog</h1>
</header>
<nav>
<a href="/">Home</a> | <a href="/about">About</a>
</nav>
<main>
<article>
<h2>Learn HTML</h2>
<p>This is the main article.</p>
</article>
<aside>
<h3>Related links</h3>
<p>Links go here.</p>
</aside>
</main>
<footer>
<p>© 2025 My Blog</p>
</footer>
</body>
</html>
Output in the browser:
This is the main article.
aside next to the article.Read HTML Semantic Elements. A div based version is in Basic HTML page layout using div tags.