Reading history

HTML Lists and Tables: ul, ol, dl, colspan, rowspan

5 min read 0 views

Learn HTML lists and tables: unordered, ordered, nested and description lists, table rows and headers, captions, colspan and rowspan.

Lists and tables organise information so readers can scan it. HTML has three kinds of list (unordered, ordered and description lists) and a set of table elements for data in rows and columns. This lesson shows how to build each one, including nested lists, table headers, captions and cells that span several columns.

In this lesson you will learn

  • Unordered, ordered and nested lists
  • Description lists for terms and definitions
  • Table structure: rows, header cells and data cells
  • <thead>, <tbody>, <tfoot> and <caption>
  • Merging cells with colspan and rowspan

Lists

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Lists</title>
</head>
<body>
  <h3>Shopping list</h3>
  <ul>
    <li>Rice</li>
    <li>Lentils</li>
    <li>Fruit
      <ul>
        <li>Mango</li>
        <li>Guava</li>
      </ul>
    </li>
  </ul>
  <h3>Steps to make tea</h3>
  <ol>
    <li>Boil water</li>
    <li>Add tea leaves</li>
    <li>Add milk and sugar</li>
  </ol>
  <dl>
    <dt>HTML</dt><dd>Structure of a web page</dd>
    <dt>CSS</dt><dd>Look and layout</dd>
  </dl>
</body>
</html>

Result

  • <ul> makes a bulleted list, for items in no particular order.
  • <ol> makes a numbered list, for steps or rankings. Attributes such as start="5" and reversed change the numbering.
  • Each item is an <li>. A nested list goes inside an <li>, not directly inside the <ul>.
  • <dl> pairs terms (<dt>) with descriptions (<dd>), as in a glossary.

Tables

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Table</title>
  <style>
    table { border-collapse: collapse; }
    th, td { border: 1px solid #999; padding: 6px 10px; }
    th { background: #e0f2f1; }
  </style>
</head>
<body>
  <table>
    <caption>Exam results</caption>
    <thead>
      <tr><th scope="col">Name</th><th scope="col">Bangla</th><th scope="col">Maths</th></tr>
    </thead>
    <tbody>
      <tr><td>Rafi</td><td>78</td><td>91</td></tr>
      <tr><td>Nila</td><td>85</td><td>88</td></tr>
    </tbody>
    <tfoot>
      <tr><td>Average</td><td colspan="2">85.5 overall</td></tr>
    </tfoot>
  </table>
</body>
</html>

Result

  • <tr> is a row; <th> is a header cell and <td> a data cell.
  • <thead>, <tbody> and <tfoot> group rows. <caption> gives the table a title.
  • scope="col" tells screen readers that a header belongs to its column.
  • colspan="2" makes a cell stretch across two columns; rowspan does the same downwards.
  • Tables have no borders by default; the CSS adds them, and border-collapse: collapse merges the double lines.

When to Use a Table

Use tables for tabular data: timetables, results, price lists. Do not use them to lay out a page; that is the job of CSS Flexbox and Grid. Layout tables confuse screen readers and are hard to make work on phones.

Common Mistakes

  1. Putting text directly inside <ul> without <li>.
  2. Using <td> with bold styling for headers instead of <th>.
  3. Rows with different numbers of cells, which break the columns. Count colspan values too.
  4. Wide tables on mobile. Wrap them in a container with overflow-x: auto.

Practice Exercises

Exercise 1. Make a numbered list that starts at 10.

Show answer
<ol start="10">
  <li>Item ten</li>
  <li>Item eleven</li>
</ol>

Exercise 2. Create a 2-row timetable where “Lunch” spans both rows of the second column.

Show answer
<table>
  <tr><td>Maths</td><td rowspan="2">Lunch</td><td>Physics</td></tr>
  <tr><td>English</td><td>Biology</td></tr>
</table>

Frequently Asked Questions

How do I remove the bullets from a list?

Use CSS: ul { list-style: none; padding-left: 0; }. This is common for navigation menus.

Can a table cell contain other HTML?

Yes. Cells can hold links, images, lists and even other tables, though nested tables are best avoided.

Summary

  • <ul>, <ol> and <dl> make bulleted, numbered and description lists.
  • Nest lists inside <li>.
  • Tables use <tr>, <th> and <td>, grouped by <thead>, <tbody> and <tfoot>.
  • Use tables for data, not for page layout.

Next: HTML Forms.

Lessons are also marked complete when you click Next.

Leave a Reply

Your email address will not be published. Required fields are marked *