The colspan attribute in the <th> tag is used to make a header cell span across multiple columns. It helps in creating grouped or merged table headers.
- Specifies the number of columns a header cell should span (positive integer, default is 1).
- Used to merge header cells horizontally.
- Helps in creating grouped table headings.
Syntax:
<th colspan="number"> Attribute Values: It contains single value number which contains the numeric value to sets the number of column a header cell should span.
Example: This example illustrates the use of colspan attribute in <th> tag.
<!--Driver Code Starts-->
<!DOCTYPE html>
<html>
<head>
<title>HTML colspan Attribute</title>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
padding: 6px;
}
</style>
</head>
<body>
<h1 style = "color: green;">GeeksforGeeks</h1>
<h2>HTML <th>colspan Attribute</h2>
<!--Driver Code Ends-->
<table>
<tr>
<th colspan="2">Expense</th>
</tr>
<tr>
<td>Arun</td>
<td>$10</td>
</tr>
<tr>
<td>Priya</td>
<td>$8</td>
</tr>
</table>
<!--Driver Code Starts-->
</body>
</html>
<!--Driver Code Ends-->