Creating Tables

Creating fancier tables

Because tables hold data, it's useful to label the columns and/or rows that are holding the information. That way, both the sighted viewer and the non-graphical environment understand better what the table is trying to communicate.

Table 1

We'll use the th (table header) tag to define a set of header cells in a table that contains information about HTML color names. The screenshot in this exercise will show you what your table will look like, so you can see what you're attempting to build. Build your table as follows. It will have 4 columns and 10 rows. Put a border of 1 on this table.

When you are putting in the background-color, alternate using the color name, the hexidecimal and rgba(r, g, b, a) syntax for specifying a color. This gives you experience using all three.

The purpose of the non-breaking space is to have some content in the td tags even though all we want to see is the background color, not any text information. You shouldn't ever have empty tags. Compare the following:
<td></td> (empty tag)
<td>&nbsp;</td> (not empty tag).

Why don't we put any data in the final column? Color is only presentational, so there is nothing for the non-graphical environment to "see." You won't need to put character entities in any table other than this one, because any table you make probably has data in each cell. I put this in here as an example of a legitimate use of the non-breaking space character entity.

color name RGB value hexadecimal value color swatch
grey 84, 84, 84 #545454  
silver 192,192, 192 #c0c0c0  
blue 0, 0, 255 #0000ff  
yellow 255, 255, 0 #ffff00  
pink 255, 192, 203 #ffc0cb  
purple 182, 0, 128 #800080  
orange 255, 165, 0 #008800  
green 0, 128, 0 #008800  
black 0, 0, 0 #000000  
CSS color designations

Table 2

This table will use table headers, rowspan, and background colors to make a visualization of a schedule. See the screenshot and emulate this as closely as you can.

Open Studio Schedule
day of week times classroom assistant
monday 10:30-11:30am Jane Doe
tuesday 8:00-10:00am john smith
wednesday 12:30-1:30pm sally jones
3:00-4:00pm Robin Davis
thursday 11:30-12:30pm sam roberts

Table 3

This table will have images as some of its table data. The screenshot will help you locate the content in the proper place, and communicate where table headers are being used.

Know Your Viburnums
Viburnum Variety Foliage Flower Fruit
Guelder Rose Bubbles pony toy Applejack pony toy Bubbles pony toy
Burkwood Bubbles pony toy Bubbles pony toy Bubbles pony toy
Southern Arrowwood Bubbles pony toy Bubbles pony toy Bubbles pony toy

Completing the table with thead and tbody

Let's go back and add a table header to the tables. Once we add a table header, we'll want to also mark up the table body. The thead and tbody are important for usability and styling; they don't "show up" by default.

Adding caption to the tables

Let's go back and add a caption to the tables. The caption goes at the top of the table, before the thead. You can control where the caption displays with a style. The property is caption-side and the value you want is bottom, if you'd like to swap the caption from the top of the table to the bottom of the table. Move at least one of your captions to the bottom of the table.

Validate your work

The border attribute will cause an error on every table that uses it, but otherwise there should be no errors.