Open In App

How to define the number of columns a cell should span using HTML5 ?

Improve
Improve
Like Article
Like
Save
Share
Report

This article will show you how a column can be made to span over multiple cells. This is done using the colspan attribute when using the <td> tag. This allows the single table cell to span the width of more than one cell or column. It provides similar functionality to the “merge cell” functions in spreadsheet programs like Excel.

Syntax:

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

Example:




<!DOCTYPE html>
<html>
  
<head>
    <style>
        body {
            text-align: center;
        }
  
        h1 {
            color: green;
        }
  
        table,
        tbody,
        td {
            border: 1px solid black;
            border-collapse: collapse;
        }
    </style>
</head>
  
<body>
    <h1>GeeksforGeeks</h1>
  
    <h2>
        How to define the number of
        columns a cell should span
        using HTML5?
    </h2>
  
    <table>
  
        <!-- The <tr> tag starts here -->
        <tr>
            <th>Name</th>
            <th>User ID</th>
        </tr>
        <tr>
            <td>Anmol</td>
            <td>345</td>
        </tr>
        <tr>
            <td>Priya</td>
            <td>567</td>
        </tr>
  
        <!-- The last row -->
        <tr>
            <!-- This td will span two 
                columns, that is a single 
                column will take up the 
                space of 2 -->
            <td colspan="2">
                Sumit: 6574
            </td>
        </tr>
    </table>
</body>
  
</html>


Output:

Supported Browsers:

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Opera
  • Safari


Last Updated : 28 Oct, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads