Chapter 7
Figure 7-8 shows the rendered output of the code from Listing 7-19. Column groupings, much like the row
groupings discussed in the previous section of this chapter, have no default visual impact on the table.
Figure 7-8. Browser output of a table with column groupings
The start tag of the colgroup element may be optional if the first element within the colgroup is a col
element and if the element is not immediately preceded by another colgroup element whose end tag has
been omitted. A colgroup element's end tag may be omitted so long as it is not immediately succeeded
by a space character or an HTML comment. Phew! Remember what we were saying earlier about
confusing tag omission rules? These are generally odd cases, but they’re worthy of note nonetheless.
The colgroup element must be an immediate child of the table element and should be included after the
caption element, if present, and before any thead, tbody, tfoot, and tr elements.
Required Attributes
There are no required attributes for the colgroup element.
Optional Attributes
In addition to the global attributes, the colgroup element has an additional optional attribute.
span: a positive integer that describes how many columns the column group
contains.
col
The col element, a void element with no content, represents one or more columns in a column group. The
col element appears as a child of a colgroup element that lacks a span attribute as shown in Listing 7-19
in the previous section on the colgroup element.
Place as many col elements within a colgroup element as you need to create a logical column grouping.
The span attribute of a col element informs the browser of how many columns the element spans. You
can even combine col elements that have the span attribute set with those that don't.
As the col element is a void element, it must have a start tag and does not have an end tag. If you prefer
XHTML syntax, you can close the col element with a trailing slash: <col />.
Required Attributes
There are no required attributes for the col element.