MAMA: Tables

By Brian Wilson

Index:

  1. Introduction
  2. How deeply are tables nested?
  3. TABLE element
  4. TD and TH elements
  5. TR element
  6. TBODY, THEAD and TFOOT elements
  7. CAPTION element
  8. COL and COLGROUP elements

Introduction

Tables have a bad reputation among the markup purists in the development community, because many authors often use them for presentation purposes. Tables generally increase the complexity of documents and can make them more difficult to maintain. Authors do not really see these factors as significant drawbacks though, judging by the overwhelming popularity of tables for layout. In practice, the use of presentation-only tables by authors is what makes the main table-related elements some of the most popular sub-elements of BODY, after the A and IMG elements. The most frequently occurring of these is the TABLE element, found in 2,894,184 of MAMA's URLs (82.47%).

Usage of the table elements

Authors have a definite preference for the table elements they use. Almost every table uses the TABLE, TR and TD elements. All of the other elements are used rarely by comparison. The CAPTION, COL, THEAD, COLGROUP, and TFOOT elements are all used in less than 1% of TABLE occurrences.

Fig 1-1: Frequency of table-related elements
ELEMENTFrequency ELEMENTFrequency
TABLE2,894,184CAPTION23,306
TD2,891,972COL21,775
TR2,891,205THEAD21,474
TBODY364,542COLGROUP12,225
TH148,344TFOOT3,947

Use of table elements together in the same page

Looking at the cases where the major table elements are used in the same document, there are thousands of instances where they are not used together. This is low considering the overall sample size. Keep in mind, that this measure only counts usage anywhere in a document—not usage together nor even correct usage. The true numbers here are likely higher as a consequence. One wonders, for example, why a TABLE would ever exist without any TD or TH elements. Leftover markup? Authoring ignorance? The plot thickens....

Fig 1-2: Table elements used together in documents
ELEMENTSFrequency
TABLE && TR2,889,207
TABLE && (TD || TH)2,892,682
TR && (TD || TH)2,890,605

How deeply are tables nested?

One of the features requested for MAMA was the ability to detect deeply-nested tables. Such structures can be excellent stress tests for a browser. In theory, every TABLE open tag should have a corresponding closing tag. As MAMA traversed a document, any TABLE open tags added 1 to the current depth counter. A closing TABLE tag would subtract 1 from the depth counter. When the depth counter hit a new high score for the document, that value became the new "maximum table depth". This rather simplistic system yielded a number for a document's "maximum table nesting depth"—it does not necessarily mean that the open and closing tags are properly nested; that is another issue entirely. The result here may be esoteric, but can still provide some entertainment.

The maximum nesting depth discovered was a rather astounding 745 deep at http://www.artsforeveryone.com/, with the next-nearest depth being 495 in a case where tables syntax was used very poorly. The average nesting depth when tables were used was 2.77. The full frequency table is also available.

Fig 2-1: URLs with highest Table-nesting depth
URLsNesting
Depth
http://www.artsforeveryone.com/745
http://mikv1.narod.ru/495
http://www.cerveceria.info/index.html409

TABLE element

This wrapper element for table structures is (naturally) the most popular of its type. It ranks #8 overall in element popularity, used in 82.47% of all MAMA's URLs. Many attributes were detected for this element, only some of which are in the standards. A few of the attributes are VERY popular with authors—Border, Width, Cellpadding, and Cellspacing are used in ~90% of all URLs that use tables. Other, less popular detected attributes are either apparently bogus (such as Cool and Celpadding) or editor extensions (like the numerous Adobe GoLive attributes Gridx/Gridy, Showgridx/Showgridy and Usegridx/Usegridy).

Fig 3-1: TABLE element/attribute usage
ELEMENT/AttributeFrequency ELEMENT/AttributeFrequency
TABLE2,894,184   Valign87,291
   Border2,691,899   Summary78,448
   Width2,637,117   Bordercolorlight76,385
   Cellpadding2,585,020   Bordercolordark73,284
   Cellspacing2,578,416   Dir60,922
   Align1,226,047   Cols35,703
   Height1,220,050   Vspace19,771
   Bgcolor893,573   Hspace19,254
   Bordercolor417,650   Rules12,628
   Background281,209   Frame9,945

The Frame attribute

This attribute for the TABLE element was first specified in HTML 4.0, and its adoption rate has not been very high—MAMA only found 9,945 URLs using it (0.34% of cases using the TABLE element). Officially, it takes one of 9 discrete values, and, as expected, they are the most popular ones. What never fails to surprise is how creative authors can be—MAMA noted 70 different total values for this attribute (some of which are listed in the full frequency table). The top value specifies no border at all, and the next most popular is a complete border—the main purpose of this attribute was to give authors more control over table borders than just a simple on/off setting, but it seems that is how authors use this attribute.

Fig 3-2: Popular Frame attribute values
(See also the complete frequency table.)
ValueFrequency ValueFrequency
void3,716vsides402
box3,147above295
border730rhs184
hsides544lhs144
below534083

The Rules attribute

This is a companion attribute to the Frame attribute covered in the previous section. The Rules and Frame attributes were both introduced at the same time in HTML 4.0 and, together, were meant to give authors complex table border control. It was discovered in 12,628 URLs (0.44% of cases using TABLE). As with Frame, many values were detected in addition to the 5 accepted values. The most popular attribute value again turns the border off completely, and the next most popular turns it on completely. Give authors the keys to the sports car, and they only use it to drive to the corner grocery store.

Fig 3-3: Popular Rules attribute values
(See also the complete frequency table.)
ValueFrequency ValueFrequency
none6,134cols840
all4,512groups426
rows1,524054

TD and TH elements

These two elements are grouped together because they mostly share the same attributes and have very similar usage. However, their usage rates could not be more different. The TD element is the most popular of all the table sub-elements, and it is the ninth most popular element overall (used in 82.41% of all URLs in MAMA and 99.92% of all URLs using the TABLE element). The TH element, on the other hand, is used in only 5.13% of URLs using the TABLE element. Because of the inherent attribute overlap between TD and TH, it can be interesting to compare attribute usage rates between the two elements. Percentages of the total element usage are also provided to help with comparisons.

Fig 4-1: TD element/attribute usage
ELEMENT/
Attribute
Frequency% Of
Element
  ELEMENT/
Attribute
Frequency% Of
Element
  ELEMENT/
Attribute
Frequency% Of
Element
TD2,891,972--    Rowspan901,30331.17%    Xpos23,1390.80%
   Width2,324,75280.39%    Background714,70624.71%    Content16,7600.58%
   Valign2,189,28775.70%    Nowrap353,57212.23%    Scope8,7220.30%
   Align1,977,36768.37%    Bordercolor131,4924.55%    Abbr2,8660.10%
   Colspan1,711,43759.18%    Bordercolorlight28,0700.97%    Headers1,0150.04%
   Height1,672,12957.82%    Bordercolordark26,2730.91%    Axis2060.01%
   Bgcolor1,306,54245.18%    Border24,1410.83%    Charoff1140.00%
Fig 4-2: TH element/attribute usage
ELEMENT/
Attribute
Frequency% Of
Element
  ELEMENT/
Attribute
Frequency% Of
Element
  ELEMENT/
Attribute
Frequency% Of
Element
TH148,344--    Height28,19519.01%    Bordercolor3,3422.25%
   Valign46,79931.55%    Bgcolor22,40615.10%    Bordercolorlight7050.48%
   Width45,70930.81%    Nowrap10,4697.06%    Bordercolordark6790.46%
   Colspan38,58726.01%    Rowspan6,3244.26%    Border1490.10%
   Align35,71024.07%    Background5,3543.61%    Axis1190.08%
   Scope30,11120.30%    Abbr5,1533.47%    Headers320.02%

TR element

This element groups table cells (TD and TH elements) into rows. It was used in 2,891,205 URLs from MAMA, or 99.90% of all URLs that used the TABLE element. Unlike its TD and TH sub-elements, authors appear to eschew the use of attributes for TR - over 60% of all the URLs that used TR elements did not carry attributes for any TR instance.

Fig 5-1: TR element/attribute usage
ELEMENT/AttributeFrequency ELEMENT/AttributeFrequency
TR2,891,205   Bordercolor24,073
   Valign642,250   Background20,028
   Align403,805   Border3,934
   Bgcolor319,779   Bordercolordark557
   Height184,333   Bordercolorlight539

TBODY, THEAD and TFOOT elements

These three elements are lumped together, but their usage varies widely. The most popular, TBODY, is only used in 12.60% of table situations. The TBODY element is almost 17 times as popular as THEAD, and TBODY leaves TFOOT in the dust by almost a factor of 100. A number of reasons could be found for the wide variation here, including editors being responsible for inflating the numbers of THEAD elements. However, we could take the semantic meaning at face value: maybe headers for tables are just not very popular. By the same token, one could say that even fewer authors are inclined to use footers for their tables. With the ever-popular usage of tables solely for layout, attaching such altruistic semantics to these elements may be folly anyway.

It would be unfair to say that authors never use attributes with these elements, but with the most popular attribute for each achieving a mere 0.25-0.4% of the overall element usage, the numbers only get worse.

Fig 6-1: TBODY, THEAD, and TFOOT element/attribute usage
ELEMENT/AttributeFrequency  ELEMENT/AttributeFrequency ELEMENT/AttributeFrequency
TBODY364,542THEAD21,474 TFOOT3,947
   Align1,386   Align52    Align15
   Valign1,092   Valign21    Valign12
   Bgcolor405   Bgcolor36    Bgcolor6

CAPTION element

This element is poorly used in MAMA's URL set—only 0.81% of all TABLE occurrences.

Fig 7-1: TR element/attribute usage
ELEMENT/AttributeFrequency
CAPTION23,306
   Align3,775
   Valign249

COL and COLGROUP elements

As with the CAPTION element, both of these elements were found to have low usage rates (less than 1% of all table usages). Most instances of the COL element (83.76%) use the Width attribute, but other detected attributes for COL and COLGROUP are used in 15% of the element's instances or less.

Fig 8-1: COL element/attribute usage
ELEMENT/AttributeFrequency ELEMENT/AttributeFrequency
COL21,775COLGROUP12,225
   Width18,238   Span993
   Span3,676   Width869
   Align1,758   Align249
   Valign1,537   Valign175
   Height88  

This article is licensed under a Creative Commons Attribution, Non Commercial - Share Alike 2.5 license.

Comments

The forum archive of this article is still available on My Opera.

No new comments accepted.