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"

Example

Here, two groups of columns are defined using the span attribute:

<table border="1">
  <colgroup width="60%" span="2"/></colgroup>
  <colgroup width="40%" span="2"/></colgroup>
  <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

If you wanted to set attributes for individual columns, you could use the col element and apply the relevant attributes to each as you saw fit. However, if a group of a columns shared the same attribute, this approach would necessitate the following repetition of seven columns:

<colgroup align="left">
  <col/>
  <col/>
  <col/>
  <col/>
  <col/>
  <col/>
  <col/>
</colgroup>

Instead, you could simply omit the nested col elements, and state how many columns were required with the span attribute, like so:

<colgroup align="left" span="7">
</colgroup>

If the colgroup contains a span attribute as well as nested col elements, the value in the span is ignored, and the number of col elements is counted instead.

Value

This attribute takes as its value a number that reflects the number of consecutive cells the colgroup represents.

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 still depends on whether the other attributes are supported. Safari, for instance, ignores the align attribute, so asking it to span that attribute across two columns has 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