View video tutorial

HTML rowspan Attribute

HTML

The HTML rowspan attribute specifies how many rows a table cell (either a <td> data cell or a <th> header cell) should span vertically.

Definition and Usage


➔ The rowspan attribute is added directly to the opening <td> or <th> tag within an HTML table.

➔ The rowspan attribute takes a positive integer value, the default value is 1 (no spanning).

Syntax
//In HTML
<table border="1">
    <tr>
        <th>Student</th>
        <th>Subject</th>
        <th>Score</th>
    </tr>
    <tr>
        <td rowspan="3" id='sample'>M John</td>
        <td>Mathematics</td>
        <td>95</td>
    </tr>
    <tr>
        <td>Physics</td>
        <td>90</td>
    </tr>
    <tr>
        <td>Chemistry</td>
        <td>88</td>
    </tr>
</table>

//In Javascript
let element=document.querySelector("#sample");
element.rowSpan = 2;
//or
element.setAttribute("rowspan", "2");

Applies to

This attribute can be used on the following element.

Attribute Element
rowspan <td>, <th>

Example

<!DOCTYPE html>
<html>
<head>
    <title>HTML rowspan attribute Example</title>
    <style>
        table,
        th,
        td {
            padding: 10px;
            text-align: center;
            border-collapse: collapse;
        }
    </style>
</head>
<body>
    <h3>HTML rowspan attribute Example</h3>
    <p>The rowspan specifies the number of rows a table cell should span vertically.
    </p>
    <table border="1">
        <tr>
            <th>Student</th>
            <th>Subject</th>
            <th>Score</th>
        </tr>
        <tr>
            <td rowspan="3" id='sample'>M John</td>
            <td>Mathematics</td>
            <td>95</td>
        </tr>
        <tr>
            <td>Physics</td>
            <td>90</td>
        </tr>
        <tr>
            <td>Chemistry</td>
            <td>88</td>
        </tr>
    </table>
</body>
</html>
Try it Now »

Click on the "Try it Now" button to see how it works.