Lesson 6 of 23

In progress

Course progress

HTML and CSS

Lists and tables, used for the right job

Group items with ordered, unordered and description lists, and build accessible data tables without using tables for layout.

Lists and tables look simple, and both are easy to misuse. A list says "these items belong together"; a table says "these values relate across rows and columns". Neither is a layout tool.

What you will learn

  • Choose between ul, ol and dl.
  • Build a table with headers that screen readers can associate with cells.
  • Recognise the layout-table anti-pattern.

Three kinds of list

ul is unordered: the order does not matter, such as features or ingredients. ol is ordered: sequence matters, such as steps. dl is a description list of term and definition pairs.

HTML
Editable. Runs in your browser.





Press Run to see the output.

Only li children belong directly inside ul or ol. If you need a paragraph inside an item, put it inside the li. Nesting a list inside an li creates a sub-list, which is correct and common for navigation.

Lists are also the standard structure for navigation. A nav containing a ul of links is easier to style and to navigate with a screen reader than a row of loose anchors.

Tables are for data

A table needs a caption, header cells and a body. th marks headers, and scope says whether a header applies down a column or across a row.

HTML
Editable. Runs in your browser.





Press Run to see the output.

caption names the table and is announced before the content, which matters when a page has several tables. thead and tbody separate structure from data; browsers use them for printing and sticky headers. scope="row" on the first cell of each row makes "Python, 30, 30" understandable instead of three numbers.

Do not merge cells casually. colspan and rowspan are valid, but they make the header associations harder to follow, and screen reader support varies. If a table needs many merged cells, a simpler layout might communicate better.

Tables are not layout

Before Flexbox and Grid, tables were used to position page sections. The result is a document that announces "table with 12 rows" before reading anything, and that collapses on a phone.

If you are reaching for a table because you want columns side by side, you want CSS layout. Keep tables for values that genuinely relate across two dimensions: prices by plan, scores by student, hours by day.

Tables also need care on narrow screens. A wide table can overflow its container, which forces the whole page to scroll sideways. The usual fix is a wrapper with overflow-x: auto and a sensible minimum width, added in the CSS module.

Lists inside tables and tables inside lists

Both are legal and sometimes right: a cell containing a list of features, or a list of tables in a report. Keep nesting shallow. If a cell contains three nested lists and a form, the data probably wants a different structure.

HTML
Editable. Runs in your browser.





Press Run to see the output.

A nested list belongs inside the li it extends, not between two li elements. Putting it outside produces invalid markup that browsers repair in different ways.

Using a table to lay out a form or a page makes the content read as tabular data and breaks down on small screens. If the goal is visual alignment, use CSS grid. A screen reader announcing "row 3, column 2" for a label is a strong sign the table is doing the wrong job.

Build a table of three tools with columns for name, price and free plan (yes or no). Add a caption and column headers, and make the tool name a row header. Then add an ordered list of three steps to get started with one of them.

Show solution
HTML
Editable. Runs in your browser.





Press Run to see the output.

The table answers "which tool, at what price, with what plan" across two dimensions. The ordered list is a sequence, which is what ol is for.

Recap

  • ul for unordered items, ol for sequence, dl for term and definition pairs.
  • A data table needs a caption, th headers and scope so cells can be associated.
  • Never use tables for page layout; that is CSS’s job.

Next, you will build forms that collect information without trapping the person filling them in.

Can I style list bullets?
Yes, with `list-style-type` and `list-style-image` in CSS. Removing bullets entirely is common for navigation, but keep the list semantics for screen readers.
Do tables need a tbody?
Browsers insert one automatically, but writing it makes the structure explicit and lets you style header and body separately.

Full syllabus

Progress is saved in this browser only. No account, no email.

Admin

About the author

Admin

Instructor and technical writer at tutorials.in

Writes beginner lessons for tutorials.in. Each lesson is checked against the language or tool documentation, and examples are run before publishing.

Reviewed by the editorial team before publishing. Last updated November 16, 2026.