Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

To create a col span in table in HTML, you use the colspan attribute.

The colspan attribute


specifies the number of columns a table cell should span.

For example, the following HTML code will create a table with a header cell that spans two
columns:

HTML
<table>
<thead>
<tr>
<th colspan="2">This header cell spans two columns</th>
</tr>
</thead>
<tbody>
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
</tr>
</tbody>
</table>

You can also use the colspan attribute to create table cells that span multiple columns in the
body of the table. For example, the following HTML code will create a table with a table cell in
the second row that spans three columns:

HTML
<table>
<thead>
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
</tr>
</thead>
<tbody>
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
<td>Cell 3</td>
</tr>
<tr>
<td colspan="3">This cell spans three columns</td>
</tr>
</tbody>
</table>

The colspan attribute is a powerful tool for creating complex and flexible tables in HTML.

Sources
1. https://www.faqcode4u.com/faq/6373/tabletbody-scrollable

You might also like