HTML rowspan Attribute

Beginner
⏱️ 4 min read
📚 Updated: Jun 2026
🎯 3 Examples
Tables & Layout

Introduction

The rowspan attribute lets a single table cell span multiple rows vertically. Use it on <td> or <th> when one label or value should cover several rows — like a category name beside multiple data rows, or a sidebar header in a timetable. Set a positive integer (e.g. rowspan="2"), then omit the matching cell in the rows below. In JavaScript, use cell.rowSpan (capital S). Not the same as rows on <textarea>.

What You’ll Learn

01

Merge Rows

Span 2, 3, or more.

02

td and th

Where it applies.

03

Integer Values

1 or greater.

04

vs colspan

Vertical vs horizontal.

05

rowSpan

DOM property.

06

Not rows

Textarea differs.

Purpose of rowspan Attribute

The primary purpose of rowspan is to control the vertical layout of tables by letting one cell cover multiple rows. This helps group related data under a single label and reduces repeated text in the first column.

For example, a product table might list three sizes under one “T-Shirt” cell with rowspan="3", instead of writing “T-Shirt” three times.

💡
rowspan vs colspan

rowspan merges cells vertically across rows. colspan merges cells horizontally across columns. You can use both on the same cell when needed.

📝 Syntax

Add rowspan to a <td> or <th> with a positive integer:

rowspan.html
<td rowspan="2">Spans two rows</td>
<th rowspan="3">Category</th>

Syntax Rules

  • Valid on <td> and <th> inside a <table>.
  • Value must be a positive integer ≥ 1.
  • A spanned cell occupies multiple row slots — skip cells in that column on following rows.
  • Each row’s effective column count must stay consistent across the table.
  • Default is rowspan="1" (single row, no merge).
  • JavaScript: cellElement.rowSpan = 3 (capital S).
  • Not valid on <textarea> — use rows for textarea height.

💎 Values

The rowspan attribute accepts a positive integer — the number of rows the cell should span:

  • rowspan="1" — Default; single row (no merge).
  • rowspan="2" — Cell covers two adjacent rows.
  • rowspan="3" — Common for category labels spanning three data rows.
rowspan-values.html
<tr>
  <th rowspan="3">Electronics</th>
  <td>Phone</td>
  <td>$499</td>
</tr>
<tr>
  <!-- no cell in column 1 — covered by rowspan -->
  <td>Tablet</td>
  <td>$299</td>
</tr>
<tr>
  <td>Laptop</td>
  <td>$899</td>
</tr>

How it Works

With rowspan="3", the first cell stretches down three rows. Rows 2 and 3 omit a cell in that column because the slot is already taken.

⚡ Quick Reference

Use Caserowspan ValueNotes
Single row cellrowspan="1"Default behavior
Merge two rowsrowspan="2"Most common merge
Category label columnrowspan="N"N = rows in group
JavaScript DOMcell.rowSpan = 3Capital S in rowSpan
Applicable elementstd, thInside table only
Horizontal mergecolspanSeparate attribute

Applicable Elements

ElementSupported?Notes
<td>YesData cells
<th>YesHeader cells; pair with scope
<table>NoSet rowspan on cells, not the table
<textarea>NoUse rows for textarea height
<div>NoTable-only attribute

rowspan vs colspan vs rows

AttributeElementDirectionPurpose
rowspantd, thVertical (rows)Merge table cells downward
colspantd, thHorizontal (columns)Merge table cells sideways
rowstextareaN/A (not a merge)Visible textarea height in lines

Examples Gallery

Basic vertical cell merge, dynamic rowSpan in JavaScript, and combining rowspan with colspan.

👀 Live Preview

Cell in column 2 spans two rows with rowspan="2":

Row 1, Cell 1Row 1–2, Cell 2 (rowspan=2)Row 1, Cell 3
Row 2, Cell 1Row 2, Cell 3
Row 3, Cell 1Row 3, Cell 2Row 3, Cell 3

Example — Basic rowspan

Merge the second column across the first two rows:

rowspan-basic.html
<table border="1">
  <tr>
    <td>Row 1, Cell 1</td>
    <td rowspan="2">Row 1–2, Cell 2 (rowspan=2)</td>
    <td>Row 1, Cell 3</td>
  </tr>
  <tr>
    <td>Row 2, Cell 1</td>
    <td>Row 2, Cell 3</td>
  </tr>
  <tr>
    <td>Row 3, Cell 1</td>
    <td>Row 3, Cell 2</td>
    <td>Row 3, Cell 3</td>
  </tr>
</table>
Try It Yourself

How It Works

The cell with rowspan="2" covers rows 1 and 2 in column 2. Row 2 has only two <td> elements because column 2 is already occupied.

Dynamic Values with JavaScript

Set vertical span programmatically with the rowSpan property:

dynamic-rowspan.html
<td id="dynamicCell">Spans 3 rows</td>

<script>
  document.getElementById("dynamicCell").rowSpan = 3;
</script>
Try It Yourself

How It Works

cell.rowSpan = 3 stretches the cell across three rows. Note the capital S in the DOM property rowSpan.

Example — rowspan + colspan

Use both attributes on one cell for a corner header block:

rowspan-colspan.html
<table border="1">
  <tr>
    <th rowspan="2" colspan="2">Sales Report</th>
    <th>Q1</th>
    <th>Q2</th>
  </tr>
  <tr>
    <th>Jan–Mar</th>
    <th>Apr–Jun</th>
  </tr>
  <tr>
    <td>North</td>
    <td>East</td>
    <td>$12k</td>
    <td>$15k</td>
  </tr>
</table>
Try It Yourself

How It Works

rowspan="2" colspan="2" makes one header cell cover a 2×2 block. Plan row and column counts carefully when combining both.

♿ Accessibility

  • Use proper headers — Pair merged header cells with scope="rowgroup" or scope="row" where appropriate.
  • Keep structure logical — Screen readers rely on consistent row and column relationships.
  • Do not over-merge — Excessive rowspan can confuse assistive technology and sighted users.
  • Caption your table — Use <caption> to describe the table purpose.
  • Test with screen readers — Verify merged cells still announce correct header associations.

🧠 How rowspan Works

1

Set rowspan on a cell

Pick how many rows one td or th should cover.

Markup
2

Omit cells below

Following rows skip that column slot.

Structure
3

Browser stretches cell

The cell grows vertically across row slots.

Layout
=

Grouped table layout

Related rows share one vertical label or value cell.

Browser Support

The rowspan attribute is supported in all modern browsers on <td> and <th> elements.

HTML5 · Fully supported

Universal vertical cell merging

All major browsers render rowspan consistently on table cells.

99% Browser support
Google Chrome Fully supported
Full support
Mozilla Firefox Fully supported
Full support
Apple Safari Fully supported
Full support
Microsoft Edge Fully supported
Full support
rowspan attribute 99% supported

Bottom line: Use rowspan confidently for table layouts; test complex merges across browsers.

💡 Best Practices

✅ Do

  • Use rowspan to group related rows under one label
  • Count cells per row — skip occupied column slots after a merge
  • Combine with colspan for corner header blocks when needed
  • Test tables across browsers and screen sizes
  • Pair header merges with scope for accessibility

❌ Don’t

  • Confuse rowspan with textarea rows
  • Leave extra cells in rows below a rowspan merge
  • Over-merge until the table is hard to read
  • Set rowspan larger than remaining rows in the table
  • Forget to validate column counts on every row

Conclusion

The rowspan attribute is a valuable tool for structured HTML tables, letting one cell cover multiple rows vertically.

Start with simple two-row merges, then build up to grouped category columns and combined rowspan + colspan headers. Always verify that each row’s effective column total stays correct.

Key Takeaways

Knowledge Unlocked

Five truths every developer should know about rowspan

Bookmark these before merging your next table rows.

5
Core concepts
📄 02

td and th

Cell elements.

Scope
🔢 03

Integer ≥ 1

Row count.

Values
⚙️ 04

rowSpan

Capital S in JS.

Script
🚫 05

Not rows

Textarea differs.

Gotcha

❓ Frequently Asked Questions

It makes a table cell span multiple rows vertically, merging adjacent row slots into one taller cell.
<td> and <th> inside a <table>. Other elements ignore rowspan.
rowspan merges table cells vertically. rows sets textarea visible height in lines.
rowspan spans rows vertically. colspan spans columns horizontally.
Use cellElement.rowSpan = 3 (capital S) or setAttribute("rowspan", "3").
Yes, on table cells in all modern browsers. Test complex table layouts for consistent rendering.

Build smarter HTML tables

Practice the rowspan attribute with vertical merges and JavaScript examples in the Try It editor.

Try rowspan example →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

3 people found this page helpful