Horje
HTML colspan Attribute

Definition and Usage

The colspan attribute defines the number of columns a table cell should span.


Applies to

The colspan attribute can be used on the following elements:

Elements Attribute
<td> colspan
<th> colspan

Browser Support

The colspan attribute has the following browser support for each element:


How to add An HTML table with a table cell that spans two columns

The td colspan attribute.
index.html
Example: HTML
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
  border: 1px solid black;
}
</style>
</head>
<body>

<h1>The td colspan attribute</h1>

<table>
  <tr>
    <th>Month</th>
    <th>Savings</th>
  </tr>
  <tr>
    <td>January</td>
    <td>$100</td>
  </tr>
  <tr>
    <td>February</td>
    <td>$80</td>
  </tr>
  <tr>
    <td colspan="2">Sum: $180</td>
  </tr>
</table>
 
</body>
</html>

Output should be:

How to add An HTML table with a table cell that spans two columns

How to add An HTML table with a header cell that spans two columns

The th colspan attribute.

index.html
Example: HTML
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
  border: 1px solid black;
}
</style>
</head>
<body>

<h1>The th colspan attribute</h1>

<table>
  <tr>
    <th colspan="2">Monthly Savings</th>
  </tr>
  <tr>
    <td>January</td>
    <td>$100</td>
  </tr>
  <tr>
    <td>February</td>
    <td>$80</td>
  </tr>
</table>

</body>
</html>

Output should be:

How to add An HTML table with a header cell that spans two columns




html colspan attribute

Type:
Develop
Category:
Web Tutorial
Sub Category:
HTML Attribute
Uploaded by:
Admin


Read Article
https://develop.horje.com/learn/1434/reference