HTML Span Attribute - W3Schools

HTML span Attribute ❮ Previous All HTML Attributes Next

Definition and Usage

The span attribute defines the number of columns a <col> or <colgroup> element should span.

Applies to

The span attribute can be used on the following elements:

Elements Attribute
<col> span
<colgroup> span

Examples

Col Example

Here, the first two columns should have a background color of red:

<table> <colgroup> <col span="2" style="background-color:red"> <col style="background-color:yellow"> </colgroup> <tr> <th>ISBN</th> <th>Title</th> <th>Price</th> </tr> <tr> <td>3476896</td> <td>My first HTML</td> <td>$53</td> </tr> </table> Try it Yourself »

Colgroup Example

Set the background color of the first two columns using the <colgroup> span attribute:

<table> <colgroup span="2" style="background:red"></colgroup> <tr> <th>ISBN</th> <th>Title</th> <th>Price</th> </tr> <tr> <td>3476896</td> <td>My first HTML</td> <td>$53</td> </tr> <tr> <td>5869207</td> <td>My first CSS</td> <td>$49</td> </tr> </table> Try it Yourself »

Browser Support

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

Element
col Yes Yes Yes Yes Yes
colgroup Yes Yes Yes Yes Yes
Previous All HTML Attributes Next +1 Sign in to track progress

Từ khóa » Thẻ Span Trong Html W3schools