πŸš€ LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Exercises.
πŸŽ“ COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.
HTML MASTER CLASS /// LEARN TAGS /// BUILD STRUCTURE /// SEMANTIC WEB /// HTML MASTER CLASS /// LEARN TAGS ///
⚑ Total XP: 0|πŸ’» html XP: 0

HTML Table Attributes: Cell Merging Math

Master HTML cell merging. Learn the strict coordinate math required to stretch cells horizontally with colspan and vertically with rowspan without breaking the table's structural integrity.

LOADING ENGINE...

Skill Matrix

UNLOCK NODES BY LEARNING NEW TAGS.

Attributes Node

Cell Manipulation Logic.


Real-world data rarely fits perfectly into a uniform, symmetrical 1x1 grid. Financial reports, class schedules, and pricing matrices often require certain data points to span across multiple columns or stretch down through multiple rows.

1Horizontal Expansion (Colspan)

To stretch a cell horizontally across a row, deploy the colspan attribute.

The value dictates exactly how many standard column slots that single cell should consume. For example, <td colspan="2"> instructs the browser engine to expand the cell to cover the width of two columns.

Grid Integrity Warning: If a row is designed for 3 columns, and you create one cell with colspan="2", you only have 1 column slot remaining in that row. You MUST manually remove the extraneous <td> tags from your HTML; otherwise, the browser will force the extra cells out of the table's structural boundaries, breaking the layout completely.

βœ•
βˆ’
+
<!-- 3-Column Grid Math -->
<table>
  <tr>
    <!-- Consumes 2 slots -->
    <th colspan="2">Mega Header</th>
    <!-- Consumes 1 slot (Total: 3) -->
    <td>Slot 3</td>
    <!-- DO NOT ADD A 4th CELL -->
  </tr>
</table>
localhost:3000
123
Mega (2)Slot 3

2Vertical Expansion (Rowspan)

While colspan stretches cells horizontally, the rowspan attribute stretches cells vertically (top-to-bottom).

If you apply <td rowspan="2">, that single cell occupies its designated slot in the current row (<tr>) AND it pushes down, forcefully occupying the corresponding slot in the row immediately beneath it.

Because it steals a slot in the subsequent row, you must physically write one fewer <td> element in that next row to prevent layout breakage.

βœ•
βˆ’
+
<!-- Rowspan Math -->
<table>
  <!-- Row 1 -->
  <tr>
    <!-- Spans down into Row 2 -->
    <td rowspan="2">Tall Cell</td>
    <td>Data A</td>
  </tr>
  <!-- Row 2 -->
  <tr>
    <!-- Tall Cell is already here -->
    <td>Data B</td>
  </tr>
</table>
localhost:3000
Tall CellData A
Data B

3Creating Complex Blocks

Can a single cell expand both horizontally and vertically? Absolutely.

By combining colspan and rowspan on the exact same <td> or <th> tag, you create a large rectangular 'block' within your grid. For instance, <td colspan="2" rowspan="2"> creates a 2x2 square that consumes a total of 4 standard grid slots.

This exponentially increases the complexity of your coordinate math, as you must account for missing slots in multiple directions simultaneously.

βœ•
βˆ’
+
<!-- Creating a 2x2 Block -->
<table>
  <tr>
    <!-- Consumes 4 slots total -->
    <td colspan="2" rowspan="2">
      Giant Block
    </td>
    <td>A</td>
  </tr>
  <tr>
    <!-- Only 1 slot left for this row -->
    <td>B</td>
  </tr>
</table>
localhost:3000
2x2 BlockA
B

?Frequently Asked Questions

Pascual Vila

Pascual Vila

Frontend Instructor // Code Syllabus

Lesson Glossary

[01]colspan

An attribute that specifies the number of columns a cell should span.

Code Preview
colspan="2"

[02]rowspan

An attribute that specifies the number of rows a cell should span.

Code Preview
rowspan="2"

[03]Grid Integrity

The state where all rows in a table account for the correct number of column slots, including merged cells.

Code Preview
Logic

[04]Cell Spanning

The act of making a table cell take up the space of multiple standard grid units.

Code Preview
UI

[05]Coordinate Logic

The mental model used to track which cells are occupied across different rows and columns.

Code Preview
Math

[06]Irregular Table

A table that does not follow a strict 1x1 grid due to the use of merging attributes.

Code Preview
Layout

Continue Learning