HTMLBasicsbeginner

HTML Tables and Lists Tutorial

Learn table tags, rowspan and colspan, ul, ol and li, nested lists and description lists, with the output of every example.

Published
TL;DR – Quick Answer

An HTML table shows data in rows and columns. Use table for the table, tr for each row, th for heading cells and td for data cells, and group rows with thead, tbody and tfoot. colspan makes a cell span several columns and rowspan makes it span several rows. HTML lists come in three kinds: ul for an unordered (bulleted) list, ol for an ordered (numbered) list, and dl for a description list. Items in ul and ol go inside li tags.

On This Page

Tables and lists are two of the most useful ways to organise content on a web page. A table shows data in rows and columns, such as a marks sheet or a timetable. A list shows a group of related items, such as steps, features or a menu.

This tutorial covers every common table tag, rowspan and colspan, and all three kinds of lists. Each example shows the code and then what the browser displays. Paste any example into our online HTML, CSS and JS editor to see it live. If you are completely new to HTML, read our HTML tutorial for beginners first.

HTML table tags

Tag Meaning
<table> The whole table
<caption> A title for the table
<tr> Table row
<th> Table heading cell (bold and centred by default)
<td> Table data cell
<thead> Groups the heading rows
<tbody> Groups the main data rows
<tfoot> Groups the footer rows, such as totals

Your first HTML table

<table border="1">
  <tr>
    <th>Name</th>
    <th>Branch</th>
    <th>Marks</th>
  </tr>
  <tr>
    <td>Ravi</td>
    <td>CSE</td>
    <td>82</td>
  </tr>
  <tr>
    <td>Priya</td>
    <td>ECE</td>
    <td>91</td>
  </tr>
</table>

Output:

+-------+--------+-------+
| Name  | Branch | Marks |
+-------+--------+-------+
| Ravi  | CSE    | 82    |
| Priya | ECE    | 91    |
+-------+--------+-------+

How to read it:

  • Each <tr> is one row going across.
  • Inside a row, each <th> or <td> is one cell.
  • Every row should have the same number of cells, unless you use colspan or rowspan.

border="1" is an old attribute that draws lines so you can see the cells while learning. In real pages, you add borders with CSS, as shown later.

A complete table with caption, thead, tbody and tfoot

<table>
  <caption>Semester 3 results</caption>
  <thead>
    <tr>
      <th scope="col">Subject</th>
      <th scope="col">Marks</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Data Structures</td>
      <td>78</td>
    </tr>
    <tr>
      <td>DBMS</td>
      <td>85</td>
    </tr>
    <tr>
      <td>Operating Systems</td>
      <td>72</td>
    </tr>
  </tbody>
  <tfoot>
    <tr>
      <th scope="row">Total</th>
      <td>235</td>
    </tr>
  </tfoot>
</table>

Output:

        Semester 3 results
+-------------------+-------+
|      Subject      | Marks |
+-------------------+-------+
| Data Structures   | 78    |
| DBMS              | 85    |
| Operating Systems | 72    |
+-------------------+-------+
|       Total       | 235   |
+-------------------+-------+

Why use these extra tags?

  • <caption> tells everyone, including screen-reader users, what the table is about.
  • <thead>, <tbody> and <tfoot> make the structure clear and easy to style. When a long table is printed, many browsers repeat the <thead> row on every page.
  • scope="col" says a heading belongs to its column. scope="row" says it belongs to its row. This helps screen readers read cells with the right heading.

colspan: a cell across columns

colspan makes one cell stretch across more than one column.

<table border="1">
  <tr>
    <th colspan="3">Student details</th>
  </tr>
  <tr>
    <th>Name</th>
    <th>Branch</th>
    <th>Year</th>
  </tr>
  <tr>
    <td>Kiran</td>
    <td>IT</td>
    <td>2</td>
  </tr>
</table>

Output:

+---------------------------+
|      Student details      |
+-------+--------+----------+
| Name  | Branch | Year     |
+-------+--------+----------+
| Kiran | IT     | 2        |
+-------+--------+----------+

The first row has only one cell, but colspan="3" makes it as wide as three cells.

rowspan: a cell down several rows

rowspan makes one cell stretch down across more than one row. A timetable is a good example:

<table border="1">
  <tr>
    <th>Day</th>
    <th>Time</th>
    <th>Subject</th>
  </tr>
  <tr>
    <td rowspan="2">Monday</td>
    <td>9 AM</td>
    <td>Java</td>
  </tr>
  <tr>
    <td>11 AM</td>
    <td>SQL</td>
  </tr>
  <tr>
    <td>Tuesday</td>
    <td>9 AM</td>
    <td>HTML and CSS</td>
  </tr>
</table>

Output:

+---------+-------+--------------+
| Day     | Time  | Subject      |
+---------+-------+--------------+
|         | 9 AM  | Java         |
| Monday  +-------+--------------+
|         | 11 AM | SQL          |
+---------+-------+--------------+
| Tuesday | 9 AM  | HTML and CSS |
+---------+-------+--------------+

Notice the third row has only two <td> cells. The "Monday" cell from the row above is already filling the first column.

Common mistake: Adding a full set of cells to the row under a rowspan. The extra cell pushes the row out of line and creates a ragged table. Count the columns already filled from above before you write each row.

Style a table with CSS

Here is the usual CSS to give a table clean borders:

<style>
  table {
    border-collapse: collapse;
    width: 100%;
  }
  th, td {
    border: 1px solid #ccc;
    padding: 8px;
    text-align: left;
  }
  thead th {
    background-color: #f2f2f2;
  }
  tbody tr:nth-child(even) {
    background-color: #fafafa;
  }
</style>
  • border-collapse: collapse merges the double borders between cells into single lines.
  • padding adds space inside each cell.
  • nth-child(even) shades every other row, which makes long tables easier to read.

Learn more about selectors like these in our CSS tutorial. Padding and borders follow the CSS box model, which explains why a cell grows when you add them.

Remember: Use tables only for data that has rows and columns. Do not use them to place parts of a page side by side. That job belongs to CSS Flexbox or CSS Grid.

HTML lists

HTML has three kinds of lists:

List Tag Item tag Use it when
Unordered list <ul> <li> Order does not matter (features, a shopping list)
Ordered list <ol> <li> Order matters (steps, rankings)
Description list <dl> <dt> and <dd> Terms with their meanings (a glossary, FAQs)

Unordered list

<h3>Skills for a Java developer</h3>
<ul>
  <li>Core Java</li>
  <li>SQL</li>
  <li>Spring Boot</li>
  <li>Git</li>
</ul>

Output:

Skills for a Java developer
  • Core Java
  • SQL
  • Spring Boot
  • Git

Ordered list

<h3>How to run a Java program</h3>
<ol>
  <li>Write the code in a file named Hello.java</li>
  <li>Open a terminal in that folder</li>
  <li>Run: java Hello.java</li>
</ol>

Output:

How to run a Java program
  1. Write the code in a file named Hello.java
  2. Open a terminal in that folder
  3. Run: java Hello.java

Ordered list attributes

Attribute What it does Example Starts like
type="A" Capital letters <ol type="A"> A, B, C
type="a" Small letters <ol type="a"> a, b, c
type="I" Roman numerals <ol type="I"> I, II, III
start Start from a number <ol start="5"> 5, 6, 7
reversed Count down <ol reversed> with 3 items 3, 2, 1

Example with type="I":

<ol type="I">
  <li>Introduction</li>
  <li>Methodology</li>
  <li>Results</li>
</ol>

Output:

  I.   Introduction
  II.  Methodology
  III. Results

Nested lists

A list can go inside a list item. Put the inner <ul> or <ol> inside the <li>, before its closing tag.

<ul>
  <li>Frontend
    <ul>
      <li>HTML</li>
      <li>CSS</li>
      <li>JavaScript</li>
    </ul>
  </li>
  <li>Backend
    <ul>
      <li>Java</li>
      <li>Spring Boot</li>
    </ul>
  </li>
</ul>

Output:

  • Frontend
      ◦ HTML
      ◦ CSS
      ◦ JavaScript
  • Backend
      ◦ Java
      ◦ Spring Boot

Browsers show a different bullet shape for each level: filled disc, then hollow circle, then square.

Common mistake: Putting the inner <ul> directly inside the outer <ul>, between two <li> tags. Only <li> elements may be direct children of <ul> and <ol>.

Description list

<dl>
  <dt>HTML</dt>
  <dd>The structure and content of a web page.</dd>
  <dt>CSS</dt>
  <dd>The look of a web page: colours, spacing and layout.</dd>
</dl>

Output:

HTML
    The structure and content of a web page.
CSS
    The look of a web page: colours, spacing and layout.

<dt> is the term and <dd> is its description, which browsers indent.

Lists as navigation menus

Most website menus are built as a list of links, then styled with CSS into a row:

<nav>
  <ul>
    <li><a href="/">Home</a></li>
    <li><a href="/courses">Courses</a></li>
    <li><a href="/contact">Contact</a></li>
  </ul>
</nav>

With CSS like ul { list-style: none; display: flex; gap: 16px; }, the bullets disappear and the items sit in one line. The CSS Flexbox guide shows a full navigation bar example.

Practice tasks

  1. Make your class timetable for one week, using rowspan for subjects that take two periods.
  2. Make a marks table with thead, tbody and a tfoot row for the total.
  3. Write a recipe with an unordered list of ingredients and an ordered list of steps.
  4. Build a nested list of your semester subjects grouped by semester.
  5. Make a glossary of five computer terms using dl, dt and dd.

Quick revision

  • A table is built from <table>, <tr>, <th> and <td>.
  • Group rows with <thead>, <tbody> and <tfoot>, and add a <caption>.
  • colspan spans columns; rowspan spans rows.
  • <ul> is bullets, <ol> is numbers, <dl> is terms and descriptions.
  • Nest a list inside an <li>, never directly inside <ul> or <ol>.

Next, learn to collect user input with HTML forms and input types, or test yourself with the HTML interview questions.

Frequently Asked Questions

What are the basic HTML table tags?
table creates the table, tr creates a row, th creates a heading cell and td creates a data cell. caption adds a title, and thead, tbody and tfoot group the header, body and footer rows.
What is the difference between rowspan and colspan?
colspan makes one cell stretch across several columns. rowspan makes one cell stretch down across several rows.
What is the difference between ordered and unordered lists?
An ordered list (ol) numbers its items because the order matters, such as steps. An unordered list (ul) shows bullets because the order does not matter, such as a shopping list.
Can I use tables for page layout?
No. Tables are for tabular data only. Use CSS Flexbox or Grid to place parts of a page side by side.
How do I start an ordered list from a different number?
Use the start attribute, such as ol start="5". You can also use reversed to count down, and type to use letters or Roman numerals.

Want to Build Your Career in Java Full Stack with AI?

Join CodeBegun and train with working industry engineers — Discover CodeBegun's Java Full Stack track

Apply for Demo Class →
Siva Prasad Galaba
Founder, CodeBegun · Staff Engineer

Founder of CodeBegun. 15+ years building Java systems at companies like Crunchyroll. Teaches Java, Spring Boot and system design the way the industry actually works, and mentors students through projects, mock interviews and placement preparation.

Technically reviewed by CodeBegun Technical TeamLast reviewed 5 December 2026 LinkedIn
Chat with us