Beginner · HTML basics · topic 9 of 64 · 30 min
Lists and tables
Explanation
Lists
A <ul> is an unordered list: the order does not matter, so it shows bullets. An <ol> is an ordered list: the order matters, so it shows numbers. Each item is an <li> (list item). Only <li> elements may sit directly inside <ul> or <ol>.
<h2>Shopping list</h2>
<ul>
<li>Atta, 5 kg</li>
<li>Toor dal, 1 kg</li>
<li>Spices
<ul>
<li>Haldi</li>
<li>Jeera</li>
</ul>
</li>
</ul>
<h2>How to make Maggi</h2>
<ol>
<li>Boil 1.5 cups of water.</li>
<li>Add the noodles and the masala.</li>
<li>Cook for 2 minutes and serve.</li>
</ol>To nest a list, put the new <ul> or <ol> inside an <li>, never directly inside the outer list. Menus, site maps and contents pages are often nested lists.
Description lists
<dl>
<dt>PNR</dt>
<dd>Passenger Name Record: the number of your train booking.</dd>
<dt>RAC</dt>
<dd>Reservation Against Cancellation: you can travel and may get a berth.</dd>
</dl>A <dl> (description list) holds pairs: a <dt> (term) and one or more <dd> (description). It suits glossaries, product details such as "Weight: 1 kg", and short question and answer lists.
Tables are for tabular data
Tabular data means information where both the rows and the columns have meaning: a timetable, a marks sheet, a price list. Never use a table to arrange the layout of a page. Layout is the job of CSS (flexbox and grid), which you will learn soon.
| Tag | Job |
|---|---|
| <table> | Holds the whole table |
| <caption> | The title of the table, shown above it |
| <thead> / <tbody> | The header rows and the body rows |
| <tr> | One table row |
| <th> | A header cell, for a column or a row |
| <td> | A normal data cell |
<table>
<caption>Trains from Pune to Mumbai</caption>
<thead>
<tr>
<th scope="col">Train</th>
<th scope="col">Departs</th>
<th scope="col">Arrives</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Deccan Queen</th>
<td>07:15</td>
<td>10:25</td>
</tr>
<tr>
<th scope="row">Pragati Express</th>
<td>07:50</td>
<td>11:25</td>
</tr>
</tbody>
</table>The scope attribute says what a header cell labels: scope="col" for a column and scope="row" for a row. A screen reader can then say "Departs, 07:15" as the user moves through the cells, instead of just "07:15".
colspan="2" makes one cell stretch across two columns, and rowspan="2" makes it stretch down two rows. After merging, every row must still add up to the same number of columns.
<table>
<caption>Marks sheet: Class 10, Term 1</caption>
<thead>
<tr><th scope="col">Subject</th><th scope="col">Theory</th><th scope="col">Practical</th></tr>
</thead>
<tbody>
<tr><th scope="row">Science</th><td>62</td><td>28</td></tr>
<tr><th scope="row">Maths</th><td>78</td><td>18</td></tr>
<tr><th scope="row" colspan="2">Total</th><td>186</td></tr>
</tbody>
</table>Watch the lesson
Lists and tables · 1/6
Lists and tables organise information so people can scan it quickly.
Prefer a video by a teacher? Find free videos on “html lists and tables tutorial for beginners” on YouTube ↗
In real life: A railway timetable and a results page
A railway enquiry page shows trains in a table with a caption such as "Trains from Pune to Mumbai", column headers (Train, Departs, Arrives) with scope="col" and the train names as row headers. A school results page uses a table for the marks sheet, an ol for the steps to apply for re-checking, and a dl to explain short forms like "AB: absent" and "CR: compartment".
Practice (0/3 done)
Turn the plain lines into real lists. The shopping items (any order) go in a <ul> with one <li> each. The recipe steps (order matters) go in an <ol> with one <li> each.
Build a train timetable as a real table. Add a <caption>, a <thead> with at least 3 column headings (<th scope="col">), and a <tbody> with at least 3 trains. Every row needs one cell for each column.
Make a small glossary of railway words with a description list: a <dl> with at least 3 terms (<dt>) and a description (<dd>) for each one. Ideas: PNR, RAC, Tatkal, Berth.
Quick quiz
Read more (free)
Pass the quiz (60% or more) or mark this topic as done when you are ready.
Your progress is saved on this device only.