Search code examples
htmlxhtmlxhtml-1.0-strictxhtml-transitional

What does the width attribute of <colgroup> actually specify?


I'm a bit unclear on what the intended use of the width attribute in the x/html <colgroup> tag is.

This reference (admittedly to the now abandoned xhtml 2.0 spec) gives an example that clearly indicates the width of the colgroup indicates the total width of the entire group of columns:

http://www.w3.org/TR/2004/WD-xhtml2-20040722/mod-tables.html

(corroborated here: http://reference.sitepoint.com/html/colgroup )

On the other hand, most other references are ambiguous about the meaning or suggest that the <colgroup> width attribute is just another shared attribute that sets the width for each individual column:

http://www.w3.org/TR/html401/struct/tables.html

(corroborated here: http://xhtml.com/en/xhtml/reference/colgroup/ )

The HTML5 spec says nothing whatsoever about a width attribute:

http://www.w3.org/TR/html5/tabular-data.html#the-colgroup-element

Has the proposed use of the width attribute in <colgroup> changed over time? The only definition that makes sense is the one given for the xhtml 2.0 spec, else the use of this is mostly redundant. The use of <colgroup> and <col> is poorly thought out, in my opinion -- too much redundancy, which is confusing to users. For example,

<colgroup span=2 align="center"/>

and

<col span=2 align="center"/>

do exactly the same thing. The small convenience of being able to collectively set attributes for a group of columns which can be individually overridden is far outweighed by the additional processing complexity of sorting all this out. Further, if width in <colgroup> doesn't apply to the total width of the referenced column group, then I would suggest that the <colgroup> tag is entirely redundant, and unnecessary save for saving a little typing. The fact that I've been researching this for a while and still don't know how to use this attribute correctly is an indication that the typical html user is not going to bother with this feature, and will at most use a collection of <col> tags to set column attributes.


Solution

  • With no clear answer to this question, I decided to try an empirical solution; namely how do the current versions of firefox (Version 37) and chrome (Version 41.0.2272.118 m) deal with <colgroup> and <col> width attributes? Using an xhtml test file with this header:

    <?xml version="1.0" encoding="iso-8859-1"?>
    <!DOCTYPE html
           PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
           "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
    

    here are the conclusions drawn from my experiments:

    • The <colgroup> width attribute applies to each <col> child and does not represent the width of the column group.
    • If width is set in a child <col> element, this overrides the width setting in the parent <colgroup>.
    • The <col> width attribute refers to the width with respect to the entire table, not just the <colgroup> parent.

    The first of these bullet items demonstrates that the idea of a <colgroup> width was just something that the xhtml2 committee came up with, and this idea died when that standard wasn't adopted. The latter two bullet items follow immediately from the first, given that width is just another cascading attribute, with no particular additional meaning when placed in a <colgroup> tag.

    Looking to the future, the HTML5 specification no longer comes with a DTD (the committee decided that a DTD wasn't expressive enough; for example, there's no way to represent the idea of "any attribute beginning with data-" in a DTD. The MS Visual Studio group did create an HTML5 Schema, which can be found here.

    Looking at the HTML5 Spec, the <colgroup>/< ambiguities I referred to in my question have been cleared up: <col> can no longer be used as a standalone <table> element, but can only appear as a child of <colgroup>.

    Looking at both the Spec and the Visual Studio schema referenced earlier, it's not clear how column width is handled at all, since this attribute doesn't appear in either the <colgroup> or <col> tags, as far as I can tell. Presumably this is to be handled strictly through the use of the style attribute.