taken from HTML5 A vocabulary and associated APIs for HTML and XHTML Editor's Draft 27 October 2009

4.9.1 The table element

Status: open issues around @summary, additions to cell. API, and @orientation

Categories
Flow content.
Contexts in which this element may be used:
Where flow content is expected.
Content model:
In this order: optionally a caption element, followed by either zero or more colgroup elements, followed optionally by a thead element, followed optionally by a tfoot element, followed by either zero or more tbody elements or one or more tr elements, followed optionally by a tfoot element (but there can only be one tfoot element child in total).
Content attributes:
Global attributes
orientation
summary
DOM interface:
interface HTMLTableElement : HTMLElement {
           attribute HTMLTableCaptionElement caption;
  HTMLElement createCaption();
  void deleteCaption();
           attribute HTMLTableSectionElement tHead;
  HTMLElement createTHead();
  void deleteTHead();
           attribute HTMLTableSectionElement tFoot;
  HTMLElement createTFoot();
  void deleteTFoot();
  readonly attribute HTMLCollection tBodies;
  HTMLElement createTBody();
  readonly attribute HTMLCollection rows;
  HTMLElement insertRow(in optional long index);
  void deleteRow(in long index);
           attribute DOMString summary;
           attriute DOMString orientation;
};

The table element represents data with more than one dimension, in the form of a table.

The table element takes part in the table model.

Tables must not be used as layout aids. Historically, some Web authors have misused tables in HTML as a way to control their page layout. This usage is non-conforming, because tools attempting to extract tabular data from such documents would obtain very confusing results. In particular, users of accessibility tools like screen readers are likely to find it very difficult to navigate pages with tables used for layout.

There are a variety of alternatives to using HTML tables for layout, primarily using CSS positioning and the CSS table model.

User agents that do table analysis on arbitrary content are encouraged to find heuristics to determine which tables actually contain data and which are merely being used for layout. This specification does not define a precise heuristic.

Tables have rows and columns given by their descendants. A table must not have an empty row or column, as described in the description of the table model.

The orientation attribute has cna have the values rows and columns, which indicate whether the table should be read in rows (horizontally), in colums (rows). rows is the default value. Auditory user agents MUST read the table according to this attribute, across rows when it is set to rows and down columns when it is set to columns. User Agents MAY make use of the orientation when splitting tables, such as for small screens or printing.   See the National Braille Association's Tape Recording Manual [http://www.rfbd.org/about.htm] for further explaination of rows and columns.

The status of the summary attribute is an open issue

The summary attribute provides a summary of the table's purpose for user agents rendering to non-visual media such as speech and Braille.

Earlier versions of HTML suggested using summary to provide structural information about the table. This version adds the orientation attribute, and methods on the cell interface that allow user agents to derive that information from the table markup.

Authors SHOULD use summary to provide information that is obvious to visual users of the table, but would be difficult to determine by navigating the table cell by cell in an auditory user agent, and which cannot be derived by the user agent from the markup. The information provided by the summary is needed by users who cannot see the table, but would usually be redundant for those who can.  Authors SHOULD use summary to highlight general idea that is to be drawn from the table, describe trends, high and low points, and the like. When a user with a non-visual user agent encounters a table, the summary should give him enough information to decide if he wishes to explore the table in detail, which can be quite time-consuming.

The information provided by the summary is needed by users who cannot see the table, but would usually be redundant for those who can. For tables where the relationships are not obvious to users who can see the layout, or in other situations where text describing the structure of the table might be useful to sighted users as well as users of screen-readers and Braille devices, it is better to describe the structure using the a caption, legend, or surrounding text instead of, or in addition to, summary. Authors MUST do this in a way that is associated with the table via markup, such that user agents and assistive technology can programmatically determine the relationship. When using summary in combination with another technique, authors MUST NOT duplicate the text, but instead use summary for the parts of the description that are only useful to users who cannot see the table.

User agents MUST expose summary text in the accessibility API on their platform as specified in the Mappings from HTML to Platform APIs document [note: This document is still under development and does not yet have a stable URL. It will have one before last call]. Visual user agents MUST NOT render summary visually in non-editing scenarios, and SHOULD render summary visually in editing scenarios. Non-visual user agents MUST render summary.

Examples:

Significant Floods of the 20th Century
[M, million; B, billion]
Flood Type Map no. Date Area or stream with flooding Reported deaths Approximate cost (uninflated) Comments
Regional flood 1 Mar.-Apr. 1913 Ohio, statewide 467 $143M Excessive regional rain.
2 Apr.-May 1927 Mississippi River from Missouri to Louisiana unknown $230M Record discharge downstream from Cairo, Illinois.
3 Mar. 1936 New England 150+ $300M Excessive rainfall on snow.
4 July 1951 Kansas and Neosho River Basins in Kansas 15 $800M Excessive regional rain.
5 Dec. 1964 - Jan. 1965 Pacific Northwest 47 $430M Excessive rainfall on snow.
Flash flood 21 June 14, 1903 Willow Creek in Oregon 225 unknown City of Heppner, Oregon, destroyed.
22 June 9-10, 1972 Rapid City, South Dakota 237 $160M 15 inches of rain in 5 hours.
23 July 31, 1976 Big Thompson and Cache la Poudre Rivers in Colorado 144 $39M Flash flood in canyon after excessive rainfall.
Ice-jam flood 25 May 1992 Yukon River Alaska 0 unknown 100-year flood on Yukon River.
Storm-surge flood 26 Sept. 1990 Galveston, Texas 6,000+ unknown Hurricane.
27 Sept. 1938 Northeast United States 494 $360M Hurricane.
Dam-failure flood 29 Feb. 2, 1972 Buffalo Creek in West Virginia 125 $60M Dam failure after excessive rainfall.
30 June 5, 1976 Teton River in Idaho 11 $400M Earthen dam breached.
Mudflow flood 32 May 18, 1980 Toutle and lower Cowlitz Rivers in Washington 60 unknown Result of eruption of Mt. St. Helens.
<table border="1" orientation="row" summary="This table lists the 32 most significant floods
of the 20th Century grouped into 6 types of floods: Regional, flash,
ice-jam, storm-surge, dam-failure, and mudflow. The majority of the
floods (20) are listed as Regional floods. There are between one and
four floods in each of the other 5 categories.  ">

The summary attribute includes the following information:

The orientation attribute in the row state indicates that the table should be read across.

<caption>Significant Floods of the 20th Century <br />
[M, million; B, billion]</caption>

The caption includes the title of the table, and a key to abbreviations used in the table for Millions and Billions. This information is needed by all users of the table, and so is in the visible caption.

<tbody>
<tr>
<th id="type">Flood Type</th>
<th id="map">Map no.</th>
<th id="date">Date</th>
<th id="area">Area or stream with flooding</th>
<th id="deaths">Reported deaths</th>
<th id="cost">Approximate cost (uninflated)</th>
<th id="comments">Comments</th>
</tr>

TH elements with ID attributes are used to associate cells with their related headers. The cell api has access to these headers

<tr>
<th rowspan="5" id="regional" scope="row">Regional flood</th>
<td headers="regional map">1</td>
<td headers="regional date">Mar.-Apr. 1913</td>
<td headers="regional area">Ohio, statewide</td>
<td headers="regional deaths">467</td>
<td headers="regional cost">$143M</td>
<td headers="regional comments">Excessive regional rain.</td>
</tr>

The first cell in this table is also a TH, and will be available via the cell API.

<tr>
<td headers="regional map">2</td>
<td headers="regional date">Apr.-May 1927</td>
<td headers="regional area">Mississippi River from Missouri to Louisiana</td>
<td headers="regional deaths">unknown</td>
<td headers="regional cost">$230M</td>
<td headers="regional comments">Record discharge downstream from Cairo, Illinois.</td>
</tr>
<tr>
<td headers="regional map">3</td>
<td headers="regional">Mar. 1936</td>
<td headers="regional">New England</td>
<td headers="regional">150+</td>
<td headers="regional">$300M</td>
<td headers="regional">Excessive rainfall on snow.</td>
</tr>
<tr>
<td headers="regional map">4</td>
<td headers="regional">July 1951</td>
<td headers="regional">Kansas and Neosho River Basins in Kansas</td>
<td headers="regional">15</td>
<td headers="regional">$800M</td>
<td headers="regional">Excessive regional rain.</td>
</tr>
<tr>
<td headers="regional map">5</td>
<td headers="regional">Dec. 1964 - Jan. 1965</td>
<td headers="regional">Pacific Northwest</td>
<td headers="regional">47</td>
<td headers="regional">$430M</td>
<td headers="regional">Excessive rainfall on snow.</td>
</tr>
<tr>
<th rowspan="3" scope="row">Flash flood</th>
<td>21</td>
<td>June 14, 1903</td>
<td>Willow Creek in Oregon</td>
<td>225</td>
<td>unknown</td>
<td>City of Heppner, Oregon, destroyed.</td>
</tr>
<tr>
<td>22</td>
<td>June 9-10, 1972</td>
<td>Rapid City, South Dakota</td>
<td>237</td>
<td>$160M</td>
<td>15 inches of rain in 5 hours.</td>
</tr>
<tr>
<td>23</td>
<td>July 31, 1976</td>
<td>Big Thompson and Cache la Poudre Rivers in Colorado</td>
<td>144</td>
<td>$39M</td>
<td>Flash flood in canyon after excessive rainfall.</td>
</tr>
<tr>
<th scope="row">Ice-jam flood</th>
<td>25</td>
<td>May 1992</td>
<td>Yukon River Alaska</td>
<td>0</td>
<td>unknown</td>
<td>100-year flood on Yukon River.</td>
</tr>
<tr>
<th rowspan="2" scope="row">Storm-surge flood</th>
<td>26</td>
<td>Sept. 1990</td>
<td>Galveston, Texas</td>
<td>6,000+</td>
<td>unknown</td>
<td>Hurricane.</td>
</tr>
<tr>
<td>27</td>
<td>Sept. 1938</td>
<td>Northeast United States</td>
<td>494</td>
<td>$360M</td>
<td>Hurricane.</td>
</tr>
<tr>
<th rowspan="2" scope="row">Dam-failure flood</th>
<td>29</td>
<td>Feb. 2, 1972</td>
<td>Buffalo Creek in West Virginia</td>
<td>125</td>
<td>$60M</td>
<td>Dam failure after excessive rainfall.</td>
</tr>
<tr>
<td>30</td>
<td>June 5, 1976</td>
<td>Teton River in Idaho</td>
<td>11</td>
<td>$400M</td>
<td>Earthen dam breached.</td>
</tr>
<tr>
<th scope="row">Mudflow flood</th>
<td>32</td>
<td>May 18, 1980</td>
<td>Toutle and lower Cowlitz Rivers in Washington</td>
<td>60</td>
<td>unknown</td>
<td>Result of eruption of Mt. St. Helens.</td>
</tr>
</tbody>
</table>

The following table has an unusual layout which will not be obvious to many users who can see it. It might benefit from a visible description explaining to the way the table is laid out, something like "Characteristics are given in the second column, with the negative side in the left column and the positive side in the right column". In this case, it is best to describe the table in visible text. The text must be marked up in such a way that assistive technologies can determine programmatically that it is a description for the table.

For instance, the following table:

Characteristics with positive and negative sides
Negative Characteristic Positive
Sad Mood Happy
Failing Grade Passing

...might benefit from a description explaining the way the table is laid out, something like "Characteristics are given in the second column, with the negative side in the left column and the positive side in the right column".

There are a variety of ways to include this information, such as:

In prose, surrounding the table
<p>In the following table, characteristics are given in the second
column, with the negative side in the left column and the positive
side in the right column.</p>
<table>
 <caption>Characteristics with positive and negative sides</caption>
 <thead>
  <tr>
   <th id="n"> Negative
   <th> Characteristic
   <th> Positive
 <tbody>
  <tr>
   <td headers="n r1"> Sad
   <th id="r1"> Mood
   <td> Happy
  <tr>
   <td headers="n r2"> Failing
   <th id="r2"> Grade
   <td> Passing
</table>
In the table's caption
<table>
 <caption>
  <strong>Characteristics with positive and negative sides.</strong>
  <p>Characteristics are given in the second column, with the
  negative side in the left column and the positive side in the right
  column.</p>
 </caption>
 <thead>
  <tr>
   <th id="n"> Negative
   <th> Characteristic
   <th> Positive
 <tbody>
  <tr>
   <td headers="n r1"> Sad
   <th id="r1"> Mood
   <td> Happy
  <tr>
   <td headers="n r2"> Failing
   <th id="r2"> Grade
   <td> Passing
</table>
In the table's caption, in a details element
<table>
 <caption>
  <strong>Characteristics with positive and negative sides.</strong>
  <details>
   <dt>Help</dt>
   <dd>
    <p>Characteristics are given in the second column, with the
    negative side in the left column and the positive side in the right
    column.</p>
   </dd>
  </details>
 </caption>
 <thead>
  <tr>
   <th id="n"> Negative
   <th> Characteristic
   <th> Positive
 <tbody>
  <tr>
   <td headers="n r1"> Sad
   <th id="r1"> Mood
   <td> Happy
  <tr>
   <td headers="n r2"> Failing
   <th id="r2"> Grade
   <td> Passing
</table>
Next to the table, in the same figure
<figure>
 <dt>Characteristics with positive and negative sides</dt>
 <dd>
  <p>Characteristics are given in the second column, with the
  negative side in the left column and the positive side in the right
  column.</p>
  <table>
   <thead>
    <tr>
     <th id="n"> Negative
     <th> Characteristic
     <th> Positive
   <tbody>
    <tr>
     <td headers="n r1"> Sad
     <th id="r1"> Mood
     <td> Happy
    <tr>
     <td headers="n r2"> Failing
     <th id="r2"> Grade
     <td> Passing
  </table>
 </dd>
</figure>
Next to the table, in a figure's dt
<figure>
 <dt>
  <strong>Characteristics with positive and negative sides</strong>
  <p>Characteristics are given in the second column, with the
  negative side in the left column and the positive side in the right
  column.</p>
 </dt>
 <dd>
  <table>
   <thead>
    <tr>
     <th id="n"> Negative
     <th> Characteristic
     <th> Positive
   <tbody>
    <tr>
     <td headers="n r1"> Sad
     <th id="r1"> Mood
     <td> Happy
    <tr>
     <td headers="n r2"> Failing
     <th id="r2"> Grade
     <td> Passing
  </table>
 </dd>
</figure>

Authors may also use other techniques, or combinations of the above techniques, as appropriate.

The best option, of course, rather than writing a description explaining the way the table is laid out, is to adjust the table such that no explanation is needed.

In the case of the table used in the examples above, a simple rearrangement of the table so that the headers are on the top and left sides removes the need for an explanation as well as removing the need for the use of headers attributes:

<table>
 <caption>Characteristics with positive and negative sides</caption>
 <thead>
  <tr>
   <th> Characteristic
   <th> Negative
   <th> Positive
 <tbody>
  <tr>
   <th> Mood
   <td> Sad
   <td> Happy
  <tr>
   <th> Grade
   <td> Failing
   <td> Passing
</table>
table . caption [ = value ]

Returns the table's caption element.

Can be set, to replace the caption element. If the new value is not a caption element, throws a HIERARCHY_REQUEST_ERR exception.

caption = table . createCaption()

Ensures the table has a caption element, and returns it.

table . deleteCaption()

Ensures the table does not have a caption element.

table . tHead [ = value ]

Returns the table's thead element.

Can be set, to replace the thead element. If the new value is not a thead element, throws a HIERARCHY_REQUEST_ERR exception.

thead = table . createTHead()

Ensures the table has a thead element, and returns it.

table . deleteTHead()

Ensures the table does not have a thead element.

table . tFoot [ = value ]

Returns the table's tfoot element.

Can be set, to replace the tfoot element. If the new value is not a tfoot element, throws a HIERARCHY_REQUEST_ERR exception.

tfoot = table . createTFoot()

Ensures the table has a tfoot element, and returns it.

table . deleteTFoot()

Ensures the table does not have a tfoot element.

table . tBodies

Returns an HTMLCollection of the tbody elements of the table.

tbody = table . createTBody()

Creates a tbody element, inserts it into the table, and returns it.

table . rows

Returns an HTMLCollection of the tr elements of the table.

tr = table . insertRow(index)

Creates a tr element, along with a tbody if required, inserts them into the table at the position given by the argument, and returns the tr.

The position is relative to the rows in the table. The index −1 is equivalent to inserting at the end of the table.

If the given position is less than −1 or greater than the number of rows, throws an INDEX_SIZE_ERR exception.

table . deleteRow(index)

Removes the tr element with the given position in the table.

The position is relative to the rows in the table. The index −1 is equivalent to deleting the last row of the table.

If the given position is less than −1 or greater than the index of the last row, or if there are no rows, throws an INDEX_SIZE_ERR exception.

The caption IDL attribute must return, on getting, the first caption element child of the table element, if any, or null otherwise. On setting, if the new value is a caption element, the first caption element child of the table element, if any, must be removed, and the new value must be inserted as the first node of the table element. If the new value is not a caption element, then a HIERARCHY_REQUEST_ERR DOM exception must be raised instead.

The createCaption() method must return the first caption element child of the table element, if any; otherwise a new caption element must be created, inserted as the first node of the table element, and then returned.

The deleteCaption() method must remove the first caption element child of the table element, if any.

The tHead IDL attribute must return, on getting, the first thead element child of the table element, if any, or null otherwise. On setting, if the new value is a thead element, the first thead element child of the table element, if any, must be removed, and the new value must be inserted immediately before the first element in the table element that is neither a caption element nor a colgroup element, if any, or at the end of the table if there are no such elements. If the new value is not a thead element, then a HIERARCHY_REQUEST_ERR DOM exception must be raised instead.

The createTHead() method must return the first thead element child of the table element, if any; otherwise a new thead element must be created and inserted immediately before the first element in the table element that is neither a caption element nor a colgroup element, if any, or at the end of the table if there are no such elements, and then that new element must be returned.

The deleteTHead() method must remove the first thead element child of the table element, if any.

The tFoot IDL attribute must return, on getting, the first tfoot element child of the table element, if any, or null otherwise. On setting, if the new value is a tfoot element, the first tfoot element child of the table element, if any, must be removed, and the new value must be inserted immediately before the first element in the table element that is neither a caption element, a colgroup element, nor a thead element, if any, or at the end of the table if there are no such elements. If the new value is not a tfoot element, then a HIERARCHY_REQUEST_ERR DOM exception must be raised instead.

The createTFoot() method must return the first tfoot element child of the table element, if any; otherwise a new tfoot element must be created and inserted immediately before the first element in the table element that is neither a caption element, a colgroup element, nor a thead element, if any, or at the end of the table if there are no such elements, and then that new element must be returned.

The deleteTFoot() method must remove the first tfoot element child of the table element, if any.

The tBodies attribute must return an HTMLCollection rooted at the table node, whose filter matches only tbody elements that are children of the table element.

The createTBody() method must create a new tbody element, insert it immediately after the last tbody element in the table element, if any, or at the end of the table element if the table element has no tbody element children, and then must return the new tbody element.

The rows attribute must return an HTMLCollection rooted at the table node, whose filter matches only tr elements that are either children of the table element, or children of thead, tbody, or tfoot elements that are themselves children of the table element. The elements in the collection must be ordered such that those elements whose parent is a thead are included first, in tree order, followed by those elements whose parent is either a table or tbody element, again in tree order, followed finally by those elements whose parent is a tfoot element, still in tree order.

The behavior of the insertRow(index) method depends on the state of the table. When it is called, the method must act as required by the first item in the following list of conditions that describes the state of the table and the index argument:

If index is less than −1 or greater than the number of elements in rows collection:
The method must raise an INDEX_SIZE_ERR exception.
If the rows collection has zero elements in it, and the table has no tbody elements in it:
The method must create a tbody element, then create a tr element, then append the tr element to the tbody element, then append the tbody element to the table element, and finally return the tr element.
If the rows collection has zero elements in it:
The method must create a tr element, append it to the last tbody element in the table, and return the tr element.
If index is missing, equal to −1, or equal to the number of items in rows collection:
The method must create a tr element, and append it to the parent of the last tr element in the rows collection. Then, the newly created tr element must be returned.
Otherwise:
The method must create a tr element, insert it immediately before the indexth tr element in the rows collection, in the same parent, and finally must return the newly created tr element.

When the deleteRow(index) method is called, the user agent must run the following steps:

  1. If index is equal to −1, then index must be set to the number if items in the rows collection, minus one.

  2. Now, if index is less than zero, or greater than or equal to the number of elements in the rows collection, the method must instead raise an INDEX_SIZE_ERR exception, and these steps must be aborted.

  3. Otherwise, the method must remove the indexth element in the rows collection from its parent.

The orientation IDL attribute must reflect the content attribute of the same name.

The summary IDL attribute must reflect the content attribute of the same name.

4.9.2 The caption element

Status: Last call for comments

Categories
None.
Contexts in which this element may be used:
As the first element child of a table element.
Content model:
Flow content, but with no descendant table elements.
Content attributes:
Global attributes
DOM interface:
interface HTMLTableCaptionElement : HTMLElement {};

The caption element represents the title of the table that is its parent, if it has a parent and that is a table element.

The caption element takes part in the table model.

When a table element is the only content in a figure element's dd, the caption element should be omitted in favor of the dt.

A caption can introduce context for a table, making it significantly easier to understand.

Consider, for instance, the following table:

1 2 3 4 5 6
1 2 3 4 5 6 7
2 3 4 5 6 7 8
3 4 5 6 7 8 9
4 5 6 7 8 9 10
5 6 7 8 9 10 11
6 7 8 9 10 11 12

In the abstract, this table is not clear. However, with a caption giving the table's number (for reference in the main prose) and explaining its use, it makes more sense:

<caption>
<p>Table 1.
<p>This table shows the total score obtained from rolling two
six-sided dice. The first row represents the value of the first die,
the first column the value of the second die. The total is given in
the cell that corresponds to the values of the two dice.
</caption>

This provides the user with more context:

Table 1.

This table shows the total score obtained from rolling two six-sided dice. The first row represents the value of the first die, the first column the value of the second die. The total is given in the cell that corresponds to the values of the two dice.

1 2 3 4 5 6
1 2 3 4 5 6 7
2 3 4 5 6 7 8
3 4 5 6 7 8 9
4 5 6 7 8 9 10
5 6 7 8 9 10 11
6 7 8 9 10 11 12

4.9.3 The colgroup element

Status: Last call for comments

Categories
None.
Contexts in which this element may be used:
As a child of a table element, after any caption elements and before any thead, tbody, tfoot, and tr elements.
Content model:
Zero or more col elements.
Content attributes:
Global attributes
span
DOM interface:
interface HTMLTableColElement : HTMLElement {
           attribute unsigned long span;
};

The colgroup element represents a group of one or more columns in the table that is its parent, if it has a parent and that is a table element.

If the colgroup element contains no col elements, then the element may have a span content attribute specified, whose value must be a valid non-negative integer greater than zero.

The colgroup element and its span attribute take part in the table model.

The span IDL attribute must reflect the content attribute of the same name. The value must be limited to only non-negative numbers greater than zero.

4.9.4 The col element

Status: Last call for comments

Categories
None.
Contexts in which this element may be used:
As a child of a colgroup element that doesn't have a span attribute.
Content model:
Empty.
Content attributes:
Global attributes
span
DOM interface:

HTMLTableColElement, same as for colgroup elements. This interface defines one member, span.

If a col element has a parent and that is a colgroup element that itself has a parent that is a table element, then the col element represents one or more columns in the column group represented by that colgroup.

The element may have a span content attribute specified, whose value must be a valid non-negative integer greater than zero.

The col element and its span attribute take part in the table model.

The span IDL attribute must reflect the content attribute of the same name. The value must be limited to only non-negative numbers greater than zero.

4.9.5 The tbody element

Status: Last call for comments

Categories
None.
Contexts in which this element may be used:
As a child of a table element, after any caption, colgroup, and thead elements, but only if there are no tr elements that are children of the table element.
Content model:
Zero or more tr elements
Content attributes:
Global attributes
DOM interface:
interface HTMLTableSectionElement : HTMLElement {
  readonly attribute HTMLCollection rows;
  HTMLElement insertRow(in optional long index);
  void deleteRow(in long index);
};

The HTMLTableSectionElement interface is also used for thead and tfoot elements.

The tbody element represents a block of rows that consist of a body of data for the parent table element, if the tbody element has a parent and it is a table.

The tbody element takes part in the table model.

tbody . rows

Returns an HTMLCollection of the tr elements of the table section.

tr = tbody . insertRow( [ index ] )

Creates a tr element, inserts it into the table section at the position given by the argument, and returns the tr.

The position is relative to the rows in the table section. The index −1, which is the default if the argument is omitted, is equivalent to inserting at the end of the table section.

If the given position is less than −1 or greater than the number of rows, throws an INDEX_SIZE_ERR exception.

tbody . deleteRow(index)

Removes the tr element with the given position in the table section.

The position is relative to the rows in the table section. The index −1 is equivalent to deleting the last row of the table section.

If the given position is less than −1 or greater than the index of the last row, or if there are no rows, throws an INDEX_SIZE_ERR exception.

The rows attribute must return an HTMLCollection rooted at the element, whose filter matches only tr elements that are children of the element.

The insertRow(index) method must, when invoked on an element table section, act as follows:

If index is less than −1 or greater than the number of elements in the rows collection, the method must raise an INDEX_SIZE_ERR exception.

If index is missing, equal to −1, or equal to the number of items in the rows collection, the method must create a tr element, append it to the element table section, and return the newly created tr element.

Otherwise, the method must create a tr element, insert it as a child of the table section element, immediately before the indexth tr element in the rows collection, and finally must return the newly created tr element.

The deleteRow(index) method must remove the indexth element in the rows collection from its parent. If index is less than zero or greater than or equal to the number of elements in the rows collection, the method must instead raise an INDEX_SIZE_ERR exception.

4.9.6 The thead element

Status: Last call for comments

Categories
None.
Contexts in which this element may be used:
As a child of a table element, after any caption, and colgroup elements and before any tbody, tfoot, and tr elements, but only if there are no other thead elements that are children of the table element.
Content model:
Zero or more tr elements
Content attributes:
Global attributes
DOM interface:
HTMLTableSectionElement, as defined for tbody elements.

The thead element represents the block of rows that consist of the column labels (headers) for the parent table element, if the thead element has a parent and it is a table.

The thead element takes part in the table model.

4.9.7 The tfoot element

Status: Last call for comments

Categories
None.
Contexts in which this element may be used:
As a child of a table element, after any caption, colgroup, and thead elements and before any tbody and tr elements, but only if there are no other tfoot elements that are children of the table element.
As a child of a table element, after any caption, colgroup, thead, tbody, and tr elements, but only if there are no other tfoot elements that are children of the table element.
Content model:
Zero or more tr elements
Content attributes:
Global attributes
DOM interface:
HTMLTableSectionElement, as defined for tbody elements.

The tfoot element represents the block of rows that consist of the column summaries (footers) for the parent table element, if the tfoot element has a parent and it is a table.

The tfoot element takes part in the table model.

4.9.8 The tr element

Status: Last call for comments

Categories
None.
Contexts in which this element may be used:
As a child of a thead element.
As a child of a tbody element.
As a child of a tfoot element.
As a child of a table element, after any caption, colgroup, and thead elements, but only if there are no tbody elements that are children of the table element.
Content model:
When the parent node is a thead element: Zero or more th elements
Otherwise: Zero or more td or th elements
Content attributes:
Global attributes
DOM interface:
interface HTMLTableRowElement : HTMLElement {
  readonly attribute long rowIndex;
  readonly attribute long sectionRowIndex;
  readonly attribute HTMLCollection cells;
  HTMLElement insertCell(in optional long index);
  void deleteCell(in long index);
};

The tr element represents a row of cells in a table.

The tr element takes part in the table model.

tr . rowIndex

Returns the position of the row in the table's rows list.

Returns −1 if the element isn't in a table.

tr . sectionRowIndex

Returns the position of the row in the table section's rows list.

Returns −1 if the element isn't in a table section.

tr . cells

Returns an HTMLCollection of the td and th elements of the row.

cell = tr . insertCell( [ index ] )

Creates a td element, inserts it into the table row at the position given by the argument, and returns the td.

The position is relative to the cells in the row. The index −1, which is the default if the argument is omitted, is equivalent to inserting at the end of the row.

If the given position is less than −1 or greater than the number of cells, throws an INDEX_SIZE_ERR exception.

tr . deleteCell(index)

Removes the td or th element with the given position in the row.

The position is relative to the cells in the row. The index −1 is equivalent to deleting the last cell of the row.

If the given position is less than −1 or greater than the index of the last cell, or if there are no cells, throws an INDEX_SIZE_ERR exception.

The rowIndex attribute must, if the element has a parent table element, or a parent tbody, thead, or tfoot element and a grandparent table element, return the index of the tr element in that table element's rows collection. If there is no such table element, then the attribute must return −1.

The sectionRowIndex attribute must, if the element has a parent table, tbody, thead, or tfoot element, return the index of the tr element in the parent element's rows collection (for tables, that's the rows collection; for table sections, that's the rows collection). If there is no such parent element, then the attribute must return −1.

The cells attribute must return an HTMLCollection rooted at the tr element, whose filter matches only td and th elements that are children of the tr element.

The insertCell(index) method must act as follows:

If index is less than −1 or greater than the number of elements in the cells collection, the method must raise an INDEX_SIZE_ERR exception.

If index is missing, equal to −1, or equal to the number of items in cells collection, the method must create a td element, append it to the tr element, and return the newly created td element.

Otherwise, the method must create a td element, insert it as a child of the tr element, immediately before the indexth td or th element in the cells collection, and finally must return the newly created td element.

The deleteCell(index) method must remove the indexth element in the cells collection from its parent. If index is less than zero or greater than or equal to the number of elements in the cells collection, the method must instead raise an INDEX_SIZE_ERR exception.

4.9.9 The td element

Status: Last call for comments

Categories
Sectioning root.
Contexts in which this element may be used:
As a child of a tr element.
Content model:
Flow content.
Content attributes:
Global attributes
colspan
rowspan
headers
DOM interface:
interface HTMLTableDataCellElement : HTMLTableCellElement {};

The td element represents a data cell in a table.

The td element and its colspan, rowspan, and headers attributes take part in the table model.

4.9.10 The th element

Status: Last call for comments

Categories
None.
Contexts in which this element may be used:
As a child of a tr element.
Content model:
Phrasing content.
Content attributes:
Global attributes
colspan
rowspan
headers
scope
DOM interface:
interface HTMLTableHeaderCellElement : HTMLTableCellElement {
           attribute DOMString scope;
};

The th element represents a header cell in a table.

The th element may have a scope content attribute specified. The scope attribute is an enumerated attribute with five states, four of which have explicit keywords:

The row keyword, which maps to the row state
The row state means the header cell applies to some of the subsequent cells in the same row(s).
The col keyword, which maps to the column state
The column state means the header cell applies to some of the subsequent cells in the same column(s).
The rowgroup keyword, which maps to the row group state
The row group state means the header cell applies to all the remaining cells in the row group. A th element's scope attribute must not be in the row group state if the element is not anchored in a row group.
The colgroup keyword, which maps to the column group state
The column group state means the header cell applies to all the remaining cells in the column group. A th element's scope attribute must not be in the column group state if the element is not anchored in a column group.
The auto state
The auto state makes the header cell apply to a set of cells selected based on context.

The scope attribute's missing value default is the auto state.

The th element and its colspan, rowspan, headers, and scope attributes take part in the table model.

The scope IDL attribute must reflect the content attribute of the same name.

The following example shows how the scope attribute's rowgroup value affects which data cells a header cell applies to.

Here is a markup fragment showing a table:

<table>
 <thead>
  <tr> <th> ID <th> Measurement <th> Average <th> Maximum
 <tbody>
  <tr> <td> <th scope=rowgroup> Cats <td> <td>
  <tr> <td> 93 <th> Legs <td> 3.5 <td> 4
  <tr> <td> 10 <th> Tails <td> 1 <td> 1
 <tbody>
  <tr> <td> <th scope=rowgroup> English speakers <td> <td>
  <tr> <td> 32 <th> Legs <td> 2.67 <td> 4
  <tr> <td> 35 <th> Tails <td> 0.33 <td> 1
</table>

This would result in the following table:

ID Measurement Average Maximum
Cats
93 Legs 3.5 4
10 Tails 1 1
English speakers
32 Legs 2.67 4
35 Tails 0.33 1

The headers in the first row all apply directly down to the rows in their column.

The headers with the explicit scope attributes apply to all the cells in their row group other than the cells in the first column.

The remaining headers apply just to the cells to the right of them.

4.9.11 Attributes common to td and th elements

Status: Last call for comments

The td and th elements may have a colspan content attribute specified, whose value must be a valid non-negative integer greater than zero.

The td and th elements may also have a rowspan content attribute specified, whose value must be a valid non-negative integer.

These attributes give the number of columns and rows respectively that the cell is to span. These attributes must not be used to overlap cells, as described in the description of the table model.


The td and th element may have a headers content attribute specified. The headers attribute, if specified, must contain a string consisting of an unordered set of unique space-separated tokens, each of which must have the value of an ID of a th element taking part in the same table as the td or th element (as defined by the table model).

A th element with ID id is said to be directly targeted by all td and th elements in the same table that have headers attributes whose values include as one of their tokens the ID id. A th element A is said to be targeted by a th or td element B if either A is directly targeted by B or if there exists an element C that is itself targeted by the element B and A is directly targeted by C.

A th element must not be targeted by itself.

The colspan, rowspan, and headers attributes take part in the table model.


The td and th elements implement interfaces that inherit from the HTMLTableCellElement interface:

interface HTMLTableCellElement : HTMLElement {
           attribute unsigned long colSpan;
           attribute unsigned long rowSpan;
           attribute DOMString headers;
  readonly attribute long cellIndex;
};
cell . cellIndex

Returns the position of the cell in the row's cells list.

Returns 0 if the element isn't in a row.

cell . cellColumnHeaders
Returns an HTMLCollection of column headers associated with this cell.
cell . cellColumnGroupHeaders
Returns an HTMLCollection of column group headers associated with this cell.
cell . cellRowHeaders
Returns an HTMLCollection of row headers associated with this cell.
cell . cellRowGroupHeaders
Returns an HTMLCollection of row group headers associated with this cell.
QUESTION:  are there implied row groups and col groups based on rowspan and colspan on th?  Should there be?

The colSpan IDL attribute must reflect the content attribute of the same name. The value must be limited to only non-negative numbers greater than zero.

The rowSpan IDL attribute must reflect the content attribute of the same name. Its default value, which must be used if parsing the attribute as a non-negative integer returns an error, is 1.

The headers IDL attribute must reflect the content attribute of the same name.

The cellIndex IDL attribute must, if the element has a parent tr element, return the index of the cell's element in the parent element's cells collection. If there is no such parent element, then the attribute must return 0.

4.9.12 Processing model

Status: Last call for comments

The various table elements and their content attributes together define the table model.

A table consists of cells aligned on a two-dimensional grid of slots with coordinates (x, y). The grid is finite, and is either empty or has one or more slots. If the grid has one or more slots, then the x coordinates are always in the range 0 ≤ x < xwidth, and the y coordinates are always in the range 0 ≤ y < yheight. If one or both of xwidth and yheight are zero, then the table is empty (has no slots). Tables correspond to table elements.

A cell is a set of slots anchored at a slot (cellx, celly), and with a particular width and height such that the cell covers all the slots with coordinates (x, y) where cellx ≤ x < cellx+width and celly ≤ y < celly+height. Cells can either be data cells or header cells. Data cells correspond to td elements, and header cells correspond to th elements. Cells of both types can have zero or more associated header cells.

It is possible, in certain error cases, for two cells to occupy the same slot.

A row is a complete set of slots from x=0 to x=xwidth-1, for a particular value of y. Rows correspond to tr elements.

A column is a complete set of slots from y=0 to y=yheight-1, for a particular value of x. Columns can correspond to col elements, but in the absence of col elements are implied.

A row group is a set of rows anchored at a slot (0, groupy) with a particular height such that the row group covers all the slots with coordinates (x, y) where 0 ≤ x < xwidth and groupy ≤ y < groupy+height. Row groups correspond to tbody, thead, and tfoot elements. Not every row is necessarily in a row group.

A column group is a set of columns anchored at a slot (groupx, 0) with a particular width such that the column group covers all the slots with coordinates (x, y) where groupx ≤ x < groupx+width and 0 ≤ y < yheight. Column groups correspond to colgroup elements. Not every column is necessarily in a column group.

Row groups cannot overlap each other. Similarly, column groups cannot overlap each other.

A cell cannot cover slots that are from two or more row groups. It is, however, possible for a cell to be in multiple column groups. All the slots that form part of one cell are part of zero or one row groups and zero or more column groups.

In addition to cells, columns, rows, row groups, and column groups, tables can have a caption element associated with them. This gives the table a heading, or legend.

A table model error is an error with the data represented by table elements and their descendants. Documents must not have table model errors.

4.9.12.1 Forming a table

Status: Last call for comments

To determine which elements correspond to which slots in a table associated with a table element, to determine the dimensions of the table (xwidth and yheight), and to determine if there are any table model errors, user agents must use the following algorithm:

  1. Let xwidth be zero.

  2. Let yheight be zero.

  3. Let pending tfoot elements be a list of tfoot elements, initially empty.

  4. Let the table be the table represented by the table element. The xwidth and yheight variables give the table's dimensions. The table is initially empty.

  5. If the table element has no children elements, then return the table (which will be empty), and abort these steps.

  6. Associate the first caption element child of the table element with the table. If there are no such children, then it has no associated caption element.

  7. Let the current element be the first element child of the table element.

    If a step in this algorithm ever requires the current element to be advanced to the next child of the table when there is no such next child, then the user agent must jump to the step labeled end, near the end of this algorithm.

  8. While the current element is not one of the following elements, advance the current element to the next child of the table:

  9. If the current element is a colgroup, follow these substeps:

    1. Column groups: Process the current element according to the appropriate case below:

      If the current element has any col element children

      Follow these steps:

      1. Let xstart have the value of xwidth.

      2. Let the current column be the first col element child of the colgroup element.

      3. Columns: If the current column col element has a span attribute, then parse its value using the rules for parsing non-negative integers.

        If the result of parsing the value is not an error or zero, then let span be that value.

        Otherwise, if the col element has no span attribute, or if trying to parse the attribute's value resulted in an error, then let span be 1.

      4. Increase xwidth by span.

      5. Let the last span columns in the table correspond to the current column col element.

      6. If current column is not the last col element child of the colgroup element, then let the current column be the next col element child of the colgroup element, and return to the step labeled columns.

      7. Let all the last columns in the table from x=xstart to x=xwidth-1 form a new column group, anchored at the slot (xstart, 0), with width xwidth-xstart, corresponding to the colgroup element.

      If the current element has no col element children
      1. If the colgroup element has a span attribute, then parse its value using the rules for parsing non-negative integers.

        If the result of parsing the value is not an error or zero, then let span be that value.

        Otherwise, if the colgroup element has no span attribute, or if trying to parse the attribute's value resulted in an error, then let span be 1.

      2. Increase xwidth by span.

      3. Let the last span columns in the table form a new column group, anchored at the slot (xwidth-span, 0), with width span, corresponding to the colgroup element.

    2. Advance the current element to the next child of the table.

    3. While the current element is not one of the following elements, advance the current element to the next child of the table:

    4. If the current element is a colgroup element, jump to the step labeled column groups above.

  10. Let ycurrent be zero.

  11. Let the list of downward-growing cells be an empty list.

  12. Rows: While the current element is not one of the following elements, advance the current element to the next child of the table:

  13. If the current element is a tr, then run the algorithm for processing rows, advance the current element to the next child of the table, and return to the step labeled rows.

  14. Run the algorithm for ending a row group.

  15. If the current element is a tfoot, then add that element to the list of pending tfoot elements, advance the current element to the next child of the table, and return to the step labeled rows.

  16. The current element is either a thead or a tbody.

    Run the algorithm for processing row groups.

  17. Advance the current element to the next child of the table.

  18. Return to the step labeled rows.

  19. End: For each tfoot element in the list of pending tfoot elements, in tree order, run the algorithm for processing row groups.

  20. If there exists a row or column in the table the table containing only slots that do not have a cell anchored to them, then this is a table model error.

  21. Return the table.

The algorithm for processing row groups, which is invoked by the set of steps above for processing thead, tbody, and tfoot elements, is:

  1. Let ystart have the value of yheight.

  2. For each tr element that is a child of the element being processed, in tree order, run the algorithm for processing rows.

  3. If yheight > ystart, then let all the last rows in the table from y=ystart to y=yheight-1 form a new row group, anchored at the slot with coordinate (0, ystart), with height yheight-ystart, corresponding to the element being processed.

  4. Run the algorithm for ending a row group.

The algorithm for ending a row group, which is invoked by the set of steps above when starting and ending a block of rows, is:

  1. While ycurrent is less than yheight, follow these steps:

    1. Run the algorithm for growing downward-growing cells.

    2. Increase ycurrent by 1.

  2. Empty the list of downward-growing cells.

The algorithm for processing rows, which is invoked by the set of steps above for processing tr elements, is:

  1. If yheight is equal to ycurrent, then increase yheight by 1. (ycurrent is never greater than yheight.)

  2. Let xcurrent be 0.

  3. Run the algorithm for growing downward-growing cells.

  4. If the tr element being processed has no td or th element children, then increase ycurrent by 1, abort this set of steps, and return to the algorithm above.

  5. Let current cell be the first td or th element in the tr element being processed.

  6. Cells: While xcurrent is less than xwidth and the slot with coordinate (xcurrent, ycurrent) already has a cell assigned to it, increase xcurrent by 1.

  7. If xcurrent is equal to xwidth, increase xwidth by 1. (xcurrent is never greater than xwidth.)

  8. If the current cell has a colspan attribute, then parse that attribute's value, and let colspan be the result.

    If parsing that value failed, or returned zero, or if the attribute is absent, then let colspan be 1, instead.

  9. If the current cell has a rowspan attribute, then parse that attribute's value, and let rowspan be the result.

    If parsing that value failed or if the attribute is absent, then let rowspan be 1, instead.

  10. If rowspan is zero, then let cell grows downward be true, and set rowspan to 1. Otherwise, let cell grows downward be false.

  11. If xwidth < xcurrent+colspan, then let xwidth be xcurrent+colspan.

  12. If yheight < ycurrent+rowspan, then let yheight be ycurrent+rowspan.

  13. Let the slots with coordinates (x, y) such that xcurrent ≤ x < xcurrent+colspan and ycurrent ≤ y < ycurrent+rowspan be covered by a new cell c, anchored at (xcurrent, ycurrent), which has width colspan and height rowspan, corresponding to the current cell element.

    If the current cell element is a th element, let this new cell c be a header cell; otherwise, let it be a data cell.

    To establish which header cells apply to the current cell element, use the algorithm for assigning header cells described in the next section.

    If any of the slots involved already had a cell covering them, then this is a table model error. Those slots now have two cells overlapping.

  14. If cell grows downward is true, then add the tuple {c, xcurrent, colspan} to the list of downward-growing cells.

  15. Increase xcurrent by colspan.

  16. If current cell is the last td or th element in the tr element being processed, then increase ycurrent by 1, abort this set of steps, and return to the algorithm above.

  17. Let current cell be the next td or th element in the tr element being processed.

  18. Return to the step labelled cells.

When the algorithms above require the user agent to run the algorithm for growing downward-growing cells, the user agent must, for each {cell, cellx, width} tuple in the list of downward-growing cells, if any, extend the cell cell so that it also covers the slots with coordinates (x, ycurrent), where cellx ≤ x < cellx+width.

4.9.12.2 Forming relationships between data cells and header cells

Status: Last call for comments

Each cell can be assigned zero or more header cells. The algorithm for assigning header cells to a cell principal cell is as follows.

  1. Let header list be an empty list of cells.

  2. Let (principalx, principaly) be the coordinate of the slot to which the principal cell is anchored.

  3. If the principal cell has a headers attribute specified
    1. Take the value of the principal cell's headers attribute and split it on spaces, letting id list be the list of tokens obtained.

    2. For each token in the id list, if the first element in the Document with an ID equal to the token is a cell in the same table, and that cell is not the principal cell, then add that cell to header list.

    If principal cell does not have a headers attribute specified
    1. Let principalwidth be the width of the principal cell.

    2. Let principalheight be the height of the principal cell.

    3. For each value of y from principaly to principaly+principalheight-1, run the internal algorithm for scanning and assigning header cells, with the principal cell, the header list, the initial coordinate (principalx,y), and the increments Δx=−1 and Δy=0.

    4. For each value of x from principalx to principalx+principalwidth-1, run the internal algorithm for scanning and assigning header cells, with the principal cell, the header list, the initial coordinate (x,principaly), and the increments Δx=0 and Δy=−1.

    5. If the principal cell is anchored in a row group, then add all header cells that are row group headers and are anchored in the same row group with an x-coordinate less than or equal to principalx+principalwidth-1 and a y-coordinate less than or equal to principaly+principalheight-1 to header list.

    6. If the principal cell is anchored in a column group, then add all header cells that are column group headers and are anchored in the same column group with an x-coordinate less than or equal to principalx+principalwidth-1 and a y-coordinate less than or equal to principaly+principalheight-1 to header list.

  4. Remove all the empty cells from the header list.

  5. Remove any duplicates from the header list.

  6. Assign the headers in the header list to the principal cell.

The internal algorithm for scanning and assigning header cells, given a principal cell, a header list, an initial coordinate (initialx, initialy), and Δx and Δy increments, is as follows:

  1. Let x equal initialx.

  2. Let y equal initialy.

  3. Let opaque headers be an empty list of cells.

  4. If principal cell is a header cell

    Let in header block be true, and let headers from current header block be a list of cells containing just the principal cell.

    Otherwise

    Let in header block be false and let headers from current header block be an empty list of cells.

  5. Loop: Increment x by Δx; increment y by Δy.

    For each invocation of this algorithm, one of Δx and Δy will be −1, and the other will be 0.

  6. If either x or y is less than 0, then abort this internal algorithm.

  7. If there is no cell covering slot (x, y), or if there is more than one cell covering slot (x, y), return to the substep marked loop.

  8. Let current cell be the cell covering slot (x, y).

  9. If current cell is a header cell
    1. Set in header block to true.

    2. Add current cell to headers from current header block.

    3. Let blocked be false.

    4. If Δx is 0

      If there are any cells in the opaque headers list anchored with the same x-coordinate as the current cell, and with the same width as current cell, then let blocked be true.

      If the current cell is not a column header, then let blocked be true.

      If Δy is 0

      If there is are any cells in the opaque headers list anchored with the same y-coordinate as the current cell, and with the same height as current cell, then let blocked be true.

      If the current cell is not a row header, then let blocked be true.

    5. If blocked is false, then add the current cell to the headers list.

    If current cell is a data cell and in header block is true

    Set in header block to false. Add all the cells in headers from current header block to the opaque headers list, and empty the headers from current header block list.

  10. Return to the step marked loop.

A header cell anchored at the slot with coordinate (x, y) with width width and height height is said to be a column header if any of the following conditions are true:

A header cell anchored at the slot with coordinate (x, y) with width width and height height is said to be a row header if any of the following conditions are true:

A header cell is said to be a column group header if its scope attribute is in the column group state.

A header cell is said to be a row group header if its scope attribute is in the row group state.

A cell is said to be an empty cell if it contains no elements and its text content, if any, consists only of White_Space characters.

4.9.13 Examples

Status: Last call for comments

This section is non-normative.

The following shows how might one mark up the bottom part of table 45 of the Smithsonian physical tables, Volume 71:

<table>
 <caption>Specification values: <b>Steel</b>, <b>Castings</b>,
 Ann. A.S.T.M. A27-16, Class B;* P max. 0.06; S max. 0.05.</caption>
 <thead>
  <tr>
   <th rowspan=2>Grade.</th>
   <th rowspan=2>Yield Point.</th>
   <th colspan=2>Ultimate tensile strength</th>
   <th rowspan=2>Per sent elong. 50.8mm or 2 in.</th>
   <th rowspan=2>Per cent reduct. area.</th>
  </tr>
  <tr>
   <th>kg/mm<sup>2</sup></th>
   <th>lb/in<sup>2</sup></th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>Hard</td>
   <td>0.45 ultimate</td>
   <td>56.2</td>
   <td>80,000</td>
   <td>15</td>
   <td>20</td>
  </tr>
  <tr>
   <td>Medium</td>
   <td>0.45 ultimate</td>
   <td>49.2</td>
   <td>70,000</td>
   <td>18</td>
   <td>25</td>
  </tr>
  <tr>
   <td>Soft</td>
   <td>0.45 ultimate</td>
   <td>42.2</td>
   <td>60,000</td>
   <td>22</td>
   <td>30</td>
  </tr>
 </tbody>
</table>

This table could look like this:

Specification values: Steel, Castings, Ann. A.S.T.M. A27-16, Class B;* P max. 0.06; S max. 0.05.
Grade. Yield Point. Ultimate tensile strength Per cent elong. 50.8 mm or 2 in. Per cent reduct. area.
kg/mm2 lb/in2
Hard 0.45 ultimate 56.2 80,000 15 20
Medium 0.45 ultimate 49.2 70,000 18 25
Soft 0.45 ultimate 42.2 60,000 22 30

The following shows how one might mark up the gross margin table on page 46 of Apple, Inc's 10-K filing for fiscal year 2008:

<table>
 <thead>
  <tr>
   <th>
   <th>2008
   <th>2007
   <th>2006
 <tbody>
  <tr>
   <th>Net sales
   <td>$ 32,479
   <td>$ 24,006
   <td>$ 19,315
  <tr>
   <th>Cost of sales
   <td>  21,334
   <td>  15,852
   <td>  13,717
 <tbody>
  <tr>
   <th>Gross margin
   <td>$ 11,145
   <td>$  8,154
   <td>$  5,598
 <tfoot>
  <tr>
   <th>Gross margin percentage
   <td>34.3%
   <td>34.0%
   <td>29.0%
</table>

This table could look like this:

2008 2007 2006
Net sales $ 32,479 $ 24,006 $ 19,315
Cost of sales 21,334 15,852 13,717
Gross margin $ 11,145 $ 8,154 $ 5,598
Gross margin percentage 34.3% 34.0% 29.0%

The following shows how one might mark up the operating expenses table from lower on the same page of that document:

<table>
 <colgroup> <col>
 <colgroup> <col> <col> <col>
 <thead>
  <tr> <th> <th>2008 <th>2007 <th>2006
 <tbody>
  <tr> <th scope=rowgroup> Research and development
       <td> $ 1,109 <td> $ 782 <td> $ 712 
  <tr> <th scope=row> Percentage of net sales
       <td> 3.4% <td> 3.3% <td> 3.7% 
 <tbody>
  <tr> <th scope=rowgroup> Selling, general, and administrative
       <td> $ 3,761 <td> $ 2,963 <td> $ 2,433 
  <tr> <th scope=row> Percentage of net sales
       <td> 11.6% <td> 12.3% <td> 12.6%
</table>

This table could look like this:

2008 2007 2006
Research and development $ 1,109 $ 782 $ 712
Percentage of net sales 3.4% 3.3% 3.7%
Selling, general, and administrative $ 3,761 $ 2,963 $ 2,433
Percentage of net sales 11.6% 12.3% 12.6%

4.10 Forms

Status: Last call for comments

Forms allow unscripted client-server interaction: given a form, a user can provide data, submit it to the server, and have the server act on it accordingly (e.g. returning the results of a search or calculation). The elements used in forms can also be used for user interaction with no associated submission mechanism, in conjunction with scripts.

Mostly for historical reasons, elements in this section fall into several overlapping (but subtly different) categories in addition to the usual ones like flow content, phrasing content, and interactive content.

A number of the elements are form-associated elements, which means they can have a form owner and, to expose this, have a form content attribute with a matching form IDL attribute.

The form-associated elements fall into several subcategories:

Listed

Denotes elements that are listed in the form.elements and fieldset.elements APIs.

Labelable

Denotes elements that can be associated with label elements.

Submittable elements

Denotes elements that can be used for constructing the form data set when a form element is submitted.

Resettable elements

Denotes elements that can be affected when a form element is reset.

In addition, some submittable elements can be, depending on their attributes, buttons. The prose below defines when an element is a button. Some buttons are specifically submit buttons.

The object element is also a form-associated element and can, with the use of a suitable plugin, partake in form submission.