HTML rowspan Attribute

Last Updated : 21 May, 2026

The rowspan attribute is used in table cells (<td> or <th>) to make a cell span across multiple rows. It helps in merging rows to create structured and flexible table layouts.

  • Specifies the number of rows a cell should span (positive integer, default is 1).
  • Used with <td> and <th> elements.
  • Used to merge cells vertically and create grouped row layouts.

Note: The rowspan attribute when used with <td> tag determines the number of standard cells it should span. 

Syntax

<td rowspan = "value">table content...</td>

It can be used with <td> and <th> elements in an HTML Table

Attribute Values

  • number: Specifies how many rows a cell spans. Use a positive integer; rowspan="0" spans remaining rows but is not reliably supported.

Using with <td> tag

The rowspan attribute, when used with the <td> tag, specifies the number of rows a table cell should span.

Syntax:

<td rowspan="value">Table content...</td>
  • The value defines how many rows the cell spans.
  • The value must be a positive integer.

Example: The implementation of rowspan attribute with the td attribute

html
<!DOCTYPE html>
<html>

<head>
    <title>HTML rowspan Attribute</title>
    <style>
        table,
        th,
        td {
            border: 1px solid black;
            border-collapse: collapse;
            padding: 6px;
        }
    </style>
</head>

<body style="text-align:center">

    <h1 style="color: green;">GeeksforGeeks</h1>
    <h2>HTML rowspan Attribute</h2>

    <table>
        <tr>
            <th>Name</th>
            <th>Age</th>
        </tr>
        <tr>
            <td>Ajay</td>
            <!-- This cell will take up space on 
                    two rows -->
            <td rowspan="2">24</td>
        </tr>
        <tr>
            <td>Priya</td>
        </tr>
    </table>

</body>

</html>

Using with <th> tag

The rowspan attribute, when used with the <th> tag, specifies the number of rows a header cell should span.

Syntax:

<th rowspan="value">Table content...</th>
  • The value defines how many rows the header cell spans.
  • The value must be a positive integer.

Example: The implementation of rowspan attribute with th attribute

html
<!DOCTYPE html>
<html>

<head>
    <title>HTML rowspan Attribute</title>
    <style>
        table,
        th,
        td {
            border: 1px solid black;
            border-collapse: collapse;
            padding: 6px;
        }
    </style>
</head>

<body style="text-align:center">
    <h1 style="color: green;">GeeksforGeeks</h1>
    <h2>HTML rowspan Attribute</h2>

    <table>
        <tr>
            <th>Name</th>
            <th>Age</th>
            <!-- This cell will take up space 
                    in 3 rows -->
            <th rowspan="3">GeeksforGeeks</th>
        </tr>
        <tr>
            <td>Arun</td>
            <td>24</td>
        </tr>
        <tr>
            <td>Priya</td>
            <td>25</td>
        </tr>
    </table>
</body>

</html>
Comment