TablesExtra· 30 min read

Spanning Cells & Accessible Tables

Merge cells across rows and columns, add a caption, and make tables friendly to screen readers.

What you will learn

  • Merge cells with colspan and rowspan
  • Add a table caption
  • Use scope for accessibility

Merging cells

Make a cell stretch across columns with colspan, or down across rows with rowspan.

colspan="2" merges two columns
<table border="1">
  <tr>
    <th colspan="2">Full Name</th>
  </tr>
  <tr>
    <td>Asha</td>
    <td>Rao</td>
  </tr>
</table>
Live preview

The first row has a single <th colspan="2">colspan="2" makes that one cell stretch across two columns, so “Full Name” spans the full width. The row below it still has two separate cells (“Asha”, “Rao”) sitting under that wide header.

Note: Output: | Full Name | (one cell spanning both columns) | Asha | Rao |

Captions and accessibility

This next table adds two finishing touches. <caption> gives the table a visible title, and the scope attribute on each header cell tells screen readers (software that reads the page aloud) which cells it labels. Read the code, then the walk-through below it.

caption + scope for clarity
<table border="1">
  <caption>Batch Schedule</caption>
  <thead>
    <tr><th scope="col">Day</th><th scope="col">Topic</th></tr>
  </thead>
  <tbody>
    <tr><th scope="row">Mon</th><td>HTML</td></tr>
    <tr><th scope="row">Tue</th><td>CSS</td></tr>
  </tbody>
</table>
Live preview

<caption> gives the whole table a title (“Batch Schedule”) shown above it. The scope attribute tells screen readers what each header labels: scope="col" means “this heads a column” and scope="row" means “this heads a row” (so “Mon” and “Tue” label their rows). Sighted users see a normal table; screen-reader users get the extra context.

Note: Output: Batch Schedule (caption above the table) Day | Topic Mon | HTML Tue | CSS

Tip: Use tables only for real tabular data (rows and columns that belong together). Do not use tables to lay out a whole page — that job belongs to CSS.

Q. Which attribute makes a cell span two columns?

Answer: colspan="2" stretches a cell across two columns. rowspan stretches across rows.

✍️ Practice

  1. Build a table with a heading cell that spans two columns using colspan.
  2. Add a <caption> and scope attributes to your timetable.

🏠 Homework

  1. Create a 2×2 “invoice” where the total row spans across using colspan.
Want to learn this with a mentor?

CodingClave runs guided, project-based training (28-day, 45-day & 6-month batches).

Explore Training →