HTML Tutorial Part 2: Lists, Links, Images and Tables
Lessons 12 to 20 of 38. Learn how to organise content with ordered, unordered and description lists, link pages together, add images with captions, and build tables.
In this part
3. Lists
- 12. Unordered List (Unordered List - <ul> and <li>)
Lists with bullet points and the types of bullets (disc, circle, square, none) - 13. Ordered List (Ordered List - <ol> and <li>)
Numbered lists: the type (1, a, A, i, I), start and reversed attributes - 14. Description List (Description List - <dl>, <dt>, <dd>)
Lists for dictionaries, glossaries and Frequently Asked Questions (FAQ) - 15. Nested Lists (Nested Lists - a list inside a list)
Building multi-level menus, sub-categories and syllabi
4. Links and Images
- 16. Hyperlinks and File Paths (Links & File Paths)
href, target, mailto, tel and Relative vs Absolute Paths - 17. Images and Captions (Images, <figure> & <figcaption>)
<img>, alt, loading='lazy', <figure>, <figcaption>
5. Tables
- 18. Basic Structure of a Table (<table>, <tr>, <th>, <td>, <caption>)
The basic anatomy of Rows, Columns and header cells - 19. Table Cell Merging (Colspan and Rowspan)
The complete logic of joining Columns and Rows together - 20. The 3 Parts of a Table (<thead>, <tbody>, <tfoot>)
The head, body and foot of a table - the professional standard for long tables
3. Lists
12. Unordered List (Unordered List - <ul> and <li>)
Lists with bullet points and the types of bullets (disc, circle, square, none)
Real-life analogy
Like a slip for buying items from a grocery shop: it makes no difference whether you buy lentils first or sugar first. Order is not important!
Explanation
Unordered list <ul>: It is used when the points of the list have no fixed order (Sequence).
- Each point is written inside a
<li>(List Item) tag. - By default, round black bullets (Disc) are shown.
- With the help of CSS you can change
list-style-type:disc: A filled round black dot (default).circle: An empty round ring.square: A square box.none: Removes the bullets (most commonly used for building navigation menu bars).
Golden rules
- Only
<li>should come directly inside<ul>, no other tag. - A website's navigation menu bar is always built with
<ul style="list-style: none;">.
Common mistake
Writing <p> or <a> directly inside <ul>. Always write <li><a>...</a></li>.
Example code
<!DOCTYPE html>
<html>
<body style="font-family: sans-serif; padding: 20px;">
<!-- Default bullets (Disc) -->
<h4 style="color: #047857; margin-bottom: 4px;">Grocery items (<ul> - Disc):</h4>
<ul style="color: #334155; line-height: 1.6;">
<li>Milk</li>
<li>Bread</li>
<li>Butter</li>
</ul>
<!-- Square bullets (Square) -->
<h4 style="color: #0284c7; margin-top: 15px; margin-bottom: 4px;">Square Bullets (Square):</h4>
<ul style="list-style-type: square; color: #334155; line-height: 1.6;">
<li>Maths notebook</li>
<li>Geometry box</li>
</ul>
</body>
</html>
Quick quiz
Which style value is used to change the bullet in an unordered list to a square?
- box
- rect
- square
- cube
Show answer
Answer: square
list-style-type: square changes the bullets into square boxes.
13. Ordered List (Ordered List - <ol> and <li>)
Numbered lists: the type (1, a, A, i, I), start and reversed attributes
Real-life analogy
Like the method for making tea: first you have to boil the water, then add the tea leaves. If you reverse the order, the tea will be ruined! Here the order (1, 2, 3) is very important.
Explanation
Ordered list <ol>: It is used when it is essential for the points of the list to be in order (Numbered).
Its main attributes:
type="1": Normal counting 1, 2, 3 (default).type="A": Capital letters A, B, C...type="a": Small letters a, b, c...type="I": Capital Roman numerals I, II, III, IV...type="i": Small Roman numerals i, ii, iii, iv...start="10": To start the counting from a particular number (for example 10, 11, 12...).reversed: To run the count backwards (10, 9, 8...) (for example top 3 winners or a countdown).
Golden rules
- If you are building an exam question paper or a step-by-step guide, always use
<ol>.
Common mistake
Manually typing 1., 2. in a paragraph. Always use <ol> so that the numbers update automatically when a new item is added.
Example code
<!DOCTYPE html>
<html>
<body style="font-family: sans-serif; padding: 20px;">
<!-- List with Roman numerals -->
<h4 style="color: #b45309; margin-bottom: 4px;">List with Roman numerals (type="I"):</h4>
<ol type="I" style="line-height: 1.6; color: #334155;">
<li>Stage one: Registration</li>
<li>Stage two: Exam</li>
<li>Stage three: Interview</li>
</ol>
<!-- Countdown (Reversed Count) -->
<h4 style="color: #dc2626; margin-top: 15px; margin-bottom: 4px;">Rocket Launch (<ol reversed start="3">):</h4>
<ol reversed start="3" style="font-weight: bold; color: #b91c1c;">
<li>Engine ignition</li>
<li>Buckle up</li>
<li>Lift-off! 🚀</li>
</ol>
</body>
</html>
Quick quiz
If you want the count of an ordered list to start from the number 5 (5, 6, 7...), which code would you write?
- <ol begin='5'>
- <ol start='5'>
- <ol from='5'>
- <ol initial='5'>
Show answer
Answer: <ol start='5'>
Using <ol start='5'> makes the count start from 5.
14. Description List (Description List - <dl>, <dt>, <dd>)
Lists for dictionaries, glossaries and Frequently Asked Questions (FAQ)
Real-life analogy
Just as in a dictionary the word is written first in thick black letters (Term) and its meaning is written below it, slightly indented (Description)!
Explanation
Description list <dl>: This is a special list that shows a term and its explanation (Definition). 3 tags work together in it:
<dl>(Description List): The main outer container of the list.<dt>(Description Term): The main word or term whose definition is to be given. It usually appears without indentation.<dd>(Description Details): The detailed description or meaning of that term. The browser automatically shifts it 40px to the right (Indent).
Golden rules
- There can be more than one
<dd>under a single<dt>(for example two meanings of one word).
Common mistake
Getting confused between dt and dd. Remember 'T' is for Term and 'D' is for Description.
Example code
<!DOCTYPE html>
<html>
<body style="font-family: sans-serif; padding: 20px;">
<h4 style="color: #0369a1; margin-top: 0;">Web Glossary (<dl>):</h4>
<dl style="font-size: 13px; line-height: 1.6;">
<dt style="font-weight: bold; color: #0284c7;">HTML</dt>
<dd style="margin-left: 20px; color: #475569;">The markup language that builds the skeleton of a web page.</dd>
<dt style="font-weight: bold; color: #0284c7; margin-top: 8px;">CSS</dt>
<dd style="margin-left: 20px; color: #475569;">The stylesheet language that gives a website colourful and beautiful design.</dd>
<dt style="font-weight: bold; color: #0284c7; margin-top: 8px;">JavaScript</dt>
<dd style="margin-left: 20px; color: #475569;">The programming language that adds brains and behaviour to a website.</dd>
</dl>
</body>
</html>
Quick quiz
Which tag is used to define the main word (Term) in a description list?
- <dl>
- <term>
- <dt>
- <dd>
Show answer
Answer: <dt>
<dt> stands for 'Description Term', which represents the main word.
15. Nested Lists (Nested Lists - a list inside a list)
Building multi-level menus, sub-categories and syllabi
Real-life analogy
Like a big cupboard with many drawers, and when you open one drawer, smaller boxes come out inside it!
Explanation
Nested list: When another new list is placed inside a point (<li>) of a list.
The most important structural rule:
The new list must always be closed inside the <li> of the parent list, not outside the <li>!
<ul>
<li>Fruits
<ul> <!-- new ul inside li -->
<li>Apple</li>
</ul>
</li> <!-- the parent li is closed here -->
</ul>
Golden rules
- A nested list must always come before the closing tag of the
<li>.
Common mistake
Starting the next <ul> after closing the parent <li>. This breaks the HTML syntax.
Example code
<!DOCTYPE html>
<html>
<body style="font-family: sans-serif; padding: 20px;">
<h4 style="color: #065f46; margin-top: 0;">Web Development Syllabus (Nested List):</h4>
<ul style="line-height: 1.6; font-size: 13px;">
<li><strong>Front-End Development</strong>
<ol type="a" style="margin-top: 4px; color: #0284c7;">
<li>HTML5 (Structure)</li>
<li>CSS3 (Styling)
<ul style="list-style-type: circle; color: #475569;">
<li>Flexbox</li>
<li>Grid</li>
</ul>
</li>
<li>JavaScript (Logic)</li>
</ol>
</li>
<li style="margin-top: 6px;"><strong>Back-End Development</strong>
<ol type="a" style="margin-top: 4px; color: #059669;">
<li>Node.js</li>
<li>Python</li>
</ol>
</li>
</ul>
</body>
</html>
Quick quiz
What is the correct syntax for creating a nested list?
- Placing <ol> immediately after <ul>
- Placing a new <ul> or <ol> inside an <li>
- Placing a new <ul> after closing the <li>
- Joining two <ul> without an <li>
Show answer
Answer: Placing a new <ul> or <ol> inside an <li>
A nested list is always contained inside the parent <li> tag.
4. Links and Images
16. Hyperlinks and File Paths (Links & File Paths)
href, target, mailto, tel and Relative vs Absolute Paths
Real-life analogy
A link is like a magic doorway (Portal): the moment you step on it, you land in another room (web page).
Explanation
1. Main types of the anchor tag <a>:
target="_blank": To open the link in a new browser tab.href="#section-id": Bookmark link! To jump straight to a particular part of the same page.mailto:email@test.com: To open the email software directly.tel:+919876543210: To open the phone dialler directly on mobile.
2. Absolute vs Relative file paths:
- Absolute Path: The full internet web address (for example
https://google.com/logo.png). - Relative Path: The address of a folder within your own website (for example
images/pic.jpg).
Golden rules
- Never give a local computer's hard-disk path (such as C:\Users...); always use a relative path.
Common mistake
Forgetting to add https:// in a link to an external website, so the link is treated as a local file and gives an error.
Example code
<!DOCTYPE html>
<html>
<body style="font-family: sans-serif; padding: 20px;">
<p><a href="https://wikipedia.org" target="_blank" style="color: #2563eb; font-weight: bold;">Wikipedia (in a new tab)</a></p>
<p><a href="mailto:parthkhurana@dailyspark.in" style="color: #059669;">Send email: parthkhurana@dailyspark.in</a></p>
<p><a href="tel:+919876543210" style="color: #d97706;">Call: +91 98765 43210</a></p>
</body>
</html>
Quick quiz
What is put in href to open the phone dialler on a mobile the moment a link is clicked?
- call:
- phone:
- tel:
- dial:
Show answer
Answer: tel:
The tel: protocol opens the phone dialler, as in href='tel:+919876543210'.
17. Images and Captions (Images, <figure> & <figcaption>)
<img>, alt, loading='lazy', <figure>, <figcaption>
Real-life analogy
The caption (photo description) written below a picture in a book works like figure and figcaption.
Explanation
Modern HTML tags for displaying images:
<img>: The main image tag (self-closing).src(address) andalt(alternative text) are mandatory. Addingloading="lazy"makes the photo load only when the user scrolls to it.<figure>and<figcaption>: A semantic container for adding an image and its official caption right below it.
Golden rules
- Always provide the
altattribute. If the photo is purely decorative, leave an emptyalt="". - Fix the image's
widthandheightin advance to prevent the page from jumping.
Common mistake
Putting a huge 5MB photo directly on the website. Always compress photos before using them.
Example code
<!DOCTYPE html>
<html>
<body style="font-family: sans-serif; padding: 20px;">
<figure style="margin: 0; max-width: 250px; border: 1px solid #cbd5e1; padding: 10px; border-radius: 8px; background: #f8fafc;">
<img src="https://images.unsplash.com/photo-1546527868-ccb7ee7dfa6a?w=300"
alt="White and brown puppy"
loading="lazy"
style="width: 100%; border-radius: 6px;">
<figcaption style="font-size: 11px; color: #64748b; text-align: center; margin-top: 6px;">
Figure 1.1: A cute little puppy (<figcaption>)
</figcaption>
</figure>
</body>
</html>
Quick quiz
Which semantic tag is used to add an official caption (description) below an image?
- <caption>
- <p>
- <figcaption>
- <title>
Show answer
Answer: <figcaption>
<figcaption> is used inside <figure> to write the description of the photo.
5. Tables
18. Basic Structure of a Table (<table>, <tr>, <th>, <td>, <caption>)
The basic anatomy of Rows, Columns and header cells
Real-life analogy
Think of a school timetable or an Excel spreadsheet, where data is organised into lines and boxes.
Explanation
The sequence of 4 basic tags for building a table:
<table>: The main container of the table.<caption>: The title of the table.<tr>: Table Row (a horizontal line).<th>: Header cell (Table Header - appears bold and centred automatically).<td>: Data cell (Table Data - a normal cell).
Golden rules
- Data must always be inside
<td>or<th>, not directly in<tr>.
Common mistake
Not adding a border to the table or writing text directly inside a cell.
Example code
<!DOCTYPE html>
<html>
<head>
<style>
table { width: 100%; border-collapse: collapse; font-family: sans-serif; font-size: 13px; }
th, td { border: 1px solid #cbd5e1; padding: 8px; text-align: left; }
th { background: #0f172a; color: white; }
tr:nth-child(even) { background: #f8fafc; }
</style>
</head>
<body style="padding: 10px;">
<table>
<caption style="font-weight: bold; margin-bottom: 6px; color: #047857;">Student Exam List</caption>
<tr>
<th>Roll No.</th>
<th>Name</th>
<th>Marks</th>
</tr>
<tr>
<td>101</td>
<td>Amit Sharma</td>
<td>95%</td>
</tr>
<tr>
<td>102</td>
<td>Priya Verma</td>
<td>98%</td>
</tr>
</table>
</body>
</html>
Quick quiz
Which tag is used to make a heading cell in a table that makes text bold by default?
- <td>
- <tr-head>
- <th>
- <header>
Show answer
Answer: <th>
<th> (Table Header) automatically shows the text bold and centred.
19. Table Cell Merging (Colspan and Rowspan)
The complete logic of joining Columns and Rows together
Real-life analogy
Just as in Excel you select two boxes and press 'Merge Cells', Colspan and Rowspan do the same thing in HTML!
Explanation
2 rules for merging cells together:
colspan="2": Horizontal merge! Joins two or more columns together sideways.rowspan="2": Vertical merge! Joins two or more rows together vertically.- Golden formula: When you put
colspan="2"on a cell, you have to remove one<td>from that same row, otherwise the table will stick out at the edge!
Golden rules
- Always keep the total number of columns consistent.
Common mistake
Not removing the extra td even after adding colspan, which leaves the table disfigured.
Example code
<!DOCTYPE html>
<html>
<head>
<style>
table { width: 100%; border-collapse: collapse; font-family: sans-serif; font-size: 13px; }
th, td { border: 1px solid #cbd5e1; padding: 8px; text-align: left; }
th { background: #0284c7; color: white; }
</style>
</head>
<body style="padding: 10px;">
<table>
<tr>
<th>Name</th>
<th colspan="2">Contact Details (Colspan=2)</th>
</tr>
<tr>
<!-- Rowspan=2: merged 2 rows -->
<td rowspan="2" style="font-weight: bold;">Rahul Kumar</td>
<td>Mobile: 9876543210</td>
<td>Email: rahul@test.com</td>
</tr>
<tr>
<td colspan="2" style="background: #f1f5f9; text-align: center;">Alternate address: New Delhi</td>
</tr>
</table>
</body>
</html>
Quick quiz
Which attribute is used to merge two rows of a table together vertically?
- colspan
- rowspan
- vert-merge
- combine
Show answer
Answer: rowspan
rowspan (Row Span) joins rows together vertically.
20. The 3 Parts of a Table (<thead>, <tbody>, <tfoot>)
The head, body and foot of a table - the professional standard for long tables
Real-life analogy
Just as a human body has a head (Head), a torso (Body) and feet (Foot), a table has 3 main parts.
Explanation
In professional web pages, tables are divided into 3 semantic parts:
<thead>: The header part of the table (column names). When a large page is printed, the header repeats itself on every page.<tbody>: The main data of the table.<tfoot>: The bottom part of the table, where the Total/Summary is shown.
Golden rules
- A table should have only one thead and only one tfoot.
Common mistake
Using tfoot without a thead.
Example code
<!DOCTYPE html>
<html>
<head>
<style>
table { width: 100%; border-collapse: collapse; font-family: sans-serif; font-size: 13px; }
th, td { border: 1px solid #cbd5e1; padding: 6px; }
</style>
</head>
<body style="padding: 10px;">
<table>
<thead style="background: #0f172a; color: white;">
<tr><th>Item</th><th>Price</th></tr>
</thead>
<tbody>
<tr><td>Book</td><td>₹300</td></tr>
<tr><td>Pen</td><td>₹50</td></tr>
</tbody>
<tfoot style="background: #e2e8f0; font-weight: bold;">
<tr><td>Total:</td><td>₹350</td></tr>
</tfoot>
</table>
</body>
</html>
Quick quiz
Which semantic tag is used to show a total or summary in the bottom part of a table?
- <bottom>
- <tfoot>
- <summary>
- <footer-row>
Show answer
Answer: <tfoot>
<tfoot> (Table Foot) is the semantic tag reserved for the bottom part of a table.