Skip to: content, navigation

by Ian Lloyd

span (HTML attribute)

Spec
Depr. Version
No HTML 4
Browser support full matrix
IE5.5+ FF1+ Saf1.3+ Op9.2+
Full Full Full Full
span="number (of columns spanned)"

Example

Here, the span is used to group the first two columns separately from the second two columns, and each group is given a different class for styling purposes:

<table border="1" cellpadding="5">
  <col class="st1" span="2"/>
  <col class="st2" span="2"/>
  <tr>
    <th colspan="4" scope="col">Work Contact Points</th>
  </tr>
  <tr>
    <th>Name</th>
    <th>Email</th>
    <th>Phone</th>
    <th>Floor/Block</th>
  </tr>
  ⋮
</table>

Description

Just as you can set th and td elements to span multiple columns using the colspan attribute, a similar result can be achieved with the col element using the span attribute (not colspan —after all, it’s obvious that it’s a col that’s being spanned!). However, using this attribute doesn’t cause any cells to be merged (as does colspan). Rather, it tells the browser how many columns or cells the attributes set in the col should apply to (including the first col). So, in the HTML example we have a table with four cells in each row—and, therefore, four columns. But only two col elements are defined, with span attributes of "2".

Value

This attribute takes as its value a number that represents the number of consecutive cells to which the col attributes should apply.

Compatibility

IE5.5Full
6.0Full
7.0Full
Firefox1.0Full
1.5Full
2.0Full
Safari1.3Full
2.0Full
3.0Full
Opera9.2Full
9.5Full

Support for this attribute has been marked as full, but be aware that this support depends on whether the other attributes are supported. For instance, Safari ignores the align attribute, so asking it to span that attribute across two columns will have no effect. In short, the successful rendering of span depends on the support for the attributes with which it’s associated.

User-contributed notes

There are no comments yet.

Add a note

To post a note on this topic, please log in with your SitePoint username and password. If you don't have an account yet, you can create a new account for free.

Related Products

The Principles of Beautiful Web Design

Best Seller!

You don’t need to go to Art School to design great looking web sites!

Book Cover: The Principles of Beautiful Web Design

Download the FREE sample chapters