Checklist for tables

This is what you should quickly check for when creating a table.

This is mostly about XHTML, but some CSS has been added to give an good example.

Summary

A table should contain a summary that describes what it contains. This to help users with screen readers understand what the table contains.

Caption

The caption is used for explaining what the tables contains. It is a short version of the summary. I usally use this as the table heading.

Table heading (th)

Table headings are used to tell what the column heading are for.

Scope

Should be used in conjunction with the table headings. This tells if the table headings are horisontal or vertical.

Table head (thead)

To group the tableheaders. Great example is when printing. If the table spans over more than one printed page. The thead can be automatically printed in the top of every page.

Table footer (tfoot)

To group the footer of the table. This should be used after the thead in the code. It will be rendered for screen at the bottom of the table. This is mostly used for helping screen readers so they do not need to go through the table to get the total, which most of the time is in the bottom right cell. See this example and try print preview.

Table body (tbody)

To group the body of the table where all the content belongs.

Colgroup

Optional, used to group columns into units.

Col

Optional, used in conjuntion with colgroup.

Example

To see the table with some style applied to it.

Code example

  1. <table cellspacing="0" summary="This an example of an table.">
  2. <caption>
  3. Table example
  4. </caption>
  5. <colgroup>
  6. <col />
  7. <col />
  8. <col />
  9. </colgroup>
  10. <thead>
  11. <tr>
  12. <th scope="col">Products</th>
  13. <th scope="col">Type</th>
  14. <th scope="col" class="alignright">Price</th>
  15. </tr>
  16. </thead>
  17. <tfoot>
  18. <tr>
  19. <td>Total</td>
  20. <td> </td>
  21. <td class="alignright">27.00$</td>
  22. </tr>
  23. </tfoot>
  24. <tbody>
  25. <tr>
  26. <td>Salmon</td>
  27. <td>Fish</td>
  28. <td class="alignright">10.00$</td>
  29. </tr>
  30. <tr>
  31. <td>Chicken</td>
  32. <td>Bird</td>
  33. <td class="alignright">5.00$</td>
  34. </tr>
  35. <tr>
  36. <td>Lamb</td>
  37. <td>Meat</td>
  38. <td class="alignright">12.00$</td>
  39. </tr>
  40. </tbody>
  41. </table>

Related Posts:

  • None

External links


Jens Wedin Mail me Portfolio