TOP CATEGORIES

×

What is Colspan in HTML?

S

Shwati Rana

html colspan attribute

Colspan in HTML

By using the colspan attribute, you can create more complex table layouts by merging cells horizontally and adjusting the overall structure of the table. And by providing the value for colspan, you can specify the number of columns the cell should span.

In short, the Colspan attribute is used to specify the number of columns that a table cell should span horizontally which allows you to merge cells across multiple columns within a table. It is used with the <td> (table data) or <th> (table header) tags.

Colspan Example

<table>

    <tr>

        <th>Header 1</th>

        <th colspan="2">Header 2</th>

    </tr>

    <tr>

        <td>Row 1, Cell 1</td>

        <td>Row 1, Cell 2</td>

        <td>Row 1, Cell 3</td>

    </tr>

</table>

According to the above example, the 2nd header cell (<th>) in the first row has a colspan attribute with a value of "2", indicating that it should span across two columns, as a result, the cell stretches horizontally to cover two columns. Similarly, each regular table cell (<td>) spans only a single column but if you wanted to merge cells and make one cell span multiple columns, you can use the colspan attribute in a similar manner.

1 votes

Your Answer

Email: advertise@gdatamart.com

Donate: To Support US

© 2024 GDATAMART.COM (All Rights Reserved)