How to define the number of columns a cell should span using HTML5 ?
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 >
< 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 >
< tr >
< 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
Share your thoughts in the comments
Please Login to comment...