HTML th Tag colspan Attribute Tutorial

In this section, we will learn what the colspan attribute is and how to use it.

What is colspan Attribute in HTML <th> Tag?

The colspan attribute is used to set the width of a header cell in terms of the number of columns.

For example, if we set the value of this attribute to 2, it means the target header cell should take up to two columns of the target table.

HTML colspan Attribute in <th> Tag Syntax:

<th colspan = “value”> </th>

<th> Tag colspan Attribute Values

The value we set for the colspan attribute defines the number of columns the target header cell should span on.

For example, if the value is set to 3, that means a width of the header cell should be wide enough to take on 3 columns.

Example: using colspan attribute in HTML <th> tag

See the Pen using colspan attribute in HTML <th> tag by Omid Dehghan (@odehghan) on CodePen.

In this example, the table has four columns. Now, because the value of the `colspan` attribute for the “First Name and Last Name” column cell is set to 2, the width of this cell becomes wide enough to take two columns.


Top Technologies