Chapter 10: Lists & Tables

Lists & Tables in HTML — two of the most frequently used ways to organize and present text content on the web.

These are not just “decorations” — they are semantic structures that tell browsers, search engines, and screen readers: “This is a group of related items” or “This is tabular data with rows and columns.”

If you use them correctly:

  • Your page becomes more accessible
  • Easier to style with CSS
  • Better for SEO
  • Looks professional even without much CSS

1. Lists in HTML – Three Main Types

HTML gives us three semantic list types. Use the right one for the job.

A. Unordered Lists <ul> + <li>

→ Bulleted lists (no specific order/sequence)

Best for:

  • Features
  • Ingredients
  • Benefits
  • Menu items
  • Things where order doesn’t matter
HTML

Default look: bullets (•) You can change style later with CSS (list-style-type: square;, disc, circle, none, etc.)

B. Ordered Lists <ol> + <li>

→ Numbered lists (order/sequence matters)

Best for:

  • Steps in a recipe/tutorial
  • Ranking
  • Instructions
  • Top 10 lists
HTML

Default: 1. 2. 3. … You can start from different number: <ol start=”5″> or use letters: <ol type=”A”>

C. Description / Definition Lists <dl> + <dt> + <dd>

→ Term + Description pairs (like a dictionary or FAQ)

Best for:

  • Glossary
  • FAQ (question → answer)
  • Product features (name → explanation)
  • Metadata (key → value)
HTML

No bullets/numbers — just term (bold-ish by default) + indented description.

2. Nesting Lists (Very Common & Powerful)

You can put lists inside lists — great for sub-items.

HTML

3. Tables in HTML – For Tabular Data Only!

Tables are not for page layout anymore (that was 2000s mistake — now we use Flexbox/Grid). Use tables only when you have real rows + columns of data.

Core structure (semantic & modern):

HTML

Key tags explained:

Tag Meaning Required? Notes
<table> The whole table Yes Container
<thead> Header section (usually one row) Recommended Stays visible when scrolling long tables
<tbody> Main data body Recommended Can have multiple
<tfoot> Footer (summary, totals) Optional Often at bottom even if written at top
<tr> Table Row Yes One per row
<th> Table Header cell For headers Bold + centered by default
<td> Table Data cell For content Normal cells

Useful attributes (add to <td> or <th>):

  • colspan=”2″ → cell spans 2 columns
  • rowspan=”3″ → cell spans 3 rows
  • scope=”col” or scope=”row” (on <th>) → improves accessibility

4. Complete Example – Lists + Table Together

index.html

HTML

style.css (basic modern look – copy-paste)

CSS

Save both files → right-click index.html → Open with Live Server.

You now have a clean page using lists for features/steps and a table for structured data.

Quick Mastery Checklist

  • Use <ul> when order doesn’t matter
  • Use <ol> when sequence/step-by-step matters
  • Use <dl> for key-value / term-description pairs
  • Never use tables for layout (only real data)
  • Always use <thead>, <tbody>, <th> for accessibility
  • Nest lists when needed (very common)

How does the page look on your screen? Feel the difference between plain paragraphs vs properly structured lists & table?

Next possible steps — tell me:

  • “now teach me how to style lists & tables beautifully”
  • “responsive tables for mobile”
  • “flexbox instead of tables for some cases”
  • “add a pricing table example”

You’re building strong foundations — keep going champ! 🚀 Chai break ho gaya? 😄

You may also like...

Leave a Reply

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