Tables
There are a number of table classes to make formatting easier. Please note that tables should only be used to display tabular data and not used to arrange blocks of text or images. When laying out text you should use the grid layouts, or box styles, or pull quotes.
By default, a <table>
has a border around the outside, no borders within and no shading. The border colour will automatically be 100 per cent of the college or uni colour.
For accessibility, all tables should have table header cells and captions. This is described below, along with instructions for changing the borders and shading.
Alignment & width
If you are using version 4 of the ANU web styles, your site will be responsive - it will change layout depending on the screen size of the user's device. For this reason, you should not set your table or column widths to pixel values.
Table alignment & width
Tables can use the standard alignment and width classes to specify where the table sits on a page and how wide it is.
For example, if you want your table to fill half width of the screen, use a 'w50' class on the table:
<table class="w50">
Column widths
If you want to control the width of columns in your table there are percentage-based classes available for use. These classes allow the table columns to lay out properly on all screen sizes. There are classes for 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 25, 75, 33 and 67 per cent of the table width.
For example:
<table class="tbl-cell-bdr">
<tr>
<th class="tbl40">40%</th>
<th class="tbl10">10%</th>
<th class="tbl25">25%</th>
<th class="tbl25">25%</th>
</tr>
<tr>
<td>-</td>
<td>-</td>
<td>-</td>
<td>-</td>
</tr>
</table>
40% | 10% | 25% | 25% |
---|---|---|---|
- | - | - | - |
Note that if the contents of a cell are wider than the class specifies, then the column width will expand to fit the content if it cannot wrap the text onto the next line (eg if there are no spaces).
Table captions
The <caption>
element is the most accessible way of providing a short descriptive title for a table. When coding a table, the <caption>
element should come immediately after the <table>
element and before anything else. Only one caption can be specified per table.
Table headers
You must add header cells by using <th>
around the table cells that contain the column or row headings. This will allow your table to be clearly understood and accessible by those viewing your site through alternative methods, such as screen readers.
Table headers are shaded with ANU tint colour, and use bold 100 per cent colour text within.
In Dreamweaver, you can make a table cell into a header cell by selecting the Header checkbox in Properties.
Heading 1 | Heading 2 |
---|---|
Cell 1 contents | Cell 2 contents |
<table>
<caption>Example table with column headers</caption>
<tbody><tr>
<th scope="col">Heading 1</th>
<th scope="col">Heading 2</th>
</tr>
<tr>
<td>Cell 1 contents</td>
<td>Cell 2 contents </td>
</tr>
</tbody>
</table>
Heading 1 | Cell 1 contents |
---|---|
Heading 2 | Cell 2 contents |
<table>
<caption>Example table with row headers</caption>
<tbody><tr>
<th scope="row">Heading 1</th>
<td>Cell 1 contents</td>
</tr>
<tr>
<th scope="row">Heading 2</th>
<td>Cell 2 contents</td>
</tr>
</tbody>
</table>
Table borders
To create a table with borders only applied to the rows:
<table class="tbl-row-bdr">
Head 1 | Head 2 |
---|---|
Cell 1 contents | Cell 2 contents |
Cell 3 contents | Cell 4 contents |
To create a table with borders only applied to the columns:
<table class="tbl-col-bdr">
Head 1 | Head 2 |
---|---|
Cell 1 contents | Cell 2 contents |
Cell 3 contents | Cell 4 contents |
To create a table with borders around every cell:
<table class="tbl-cell-bdr">
Head 1 | Head 2 |
---|---|
Cell 1 contents | Cell 2 contents |
Cell 3 contents | Cell 4 contents |
To create a table with a border around the outside and extra space between the cells:
<table class="tbl-space">
Shading is not included by default, but has been added here so that you can see the extra space between cells.
Head 1 | Head 2 |
---|---|
Cell 1 contents | Cell 2 contents |
Cell 3 contents | Cell 4 contents |
You can remove the outer border from a table by adding the class noborder
.
For example, the following table is set to have row borders but no outer border:
<table class="tbl-row-bdr noborder">
Head 1 | Head 2 |
---|---|
Cell 1 contents | Cell 2 contents |
Cell 3 contents | Cell 4 contents |
On College websites tables will be College colour by default. To override this with University colour, use:
tbl-tint
- all table elementstbl-row-bdr-tint
- row borders onlytbl-col-bdr-tint
- column borders onlytbl-cell-bdr-tint
- all cell borders
Table shading
Tables can be shaded using the appropriate background colour class on the table, row or cell. For example:
<table class="tbl-row-bdr noborder bg-tint>
Head 1 | Head 2 |
---|---|
Cell 1 contents | Cell 2 contents |
Cell 3 contents | Cell 4 contents |
Row shading
<table class="tbl-space"><tr><th>...</tr><tr class="bg-tint">...</table>
Head 1 | Head 2 |
---|---|
Cell 1 contents | Cell 2 contents |
Cell 3 contents | Cell 4 contents |
Cell shading
<table class="tbl-col-bdr"><tr><th>...<tr><td class="bg-tint">...</table>
Head 1 | Head 2 |
---|---|
Cell 1 contents | Cell 2 contents |
Cell 3 contents | Cell 4 contents |
Floating table headers for long tables
If you have a long table that is likely to take up more than one page, you can use floating table headers to make sure the first row of the table is always visible. To create a table with a floating header, you will need to do two things:
- add the class 'anu-long-area' to the table
- add the class 'anu-sticky-header' to the first table row
Note: the sticky header will not work in Internet Explorer 7, but should work in more modern browsers.
<table class="tbl-cell-bdr anu-long-area">
<tr class="anu-sticky-header">
<th>Heading 1</th>
<th>Heading 2</th>
</tr>
<tr>
<td>Some data in a table</td>
<td>Some more data</td>
</tr>
<tr>
<td>Some data in a table</td>
<td>Some more data</td>
</tr>
...
</table>
Heading 1 | Heading 2 |
---|---|
Some data in a table | Some more data |
Some data in a table | Some more data |
Some data in a table | Some more data |
Some data in a table | Some more data |
Some data in a table | Some more data |
Some data in a table | Some more data |
Some data in a table | Some more data |
Some data in a table | Some more data |
Some data in a table | Some more data |
Some data in a table | Some more data |
Some data in a table | Some more data |
Some data in a table | Some more data |
Some data in a table | Some more data |
Some data in a table | Some more data |
Some data in a table | Some more data |
Some data in a table | Some more data |
Some data in a table | Some more data |
Some data in a table | Some more data |
Some data in a table | Some more data |
Some data in a table | Some more data |
Some data in a table | Some more data |
Some data in a table | Some more data |
Some data in a table | Some more data |
Some data in a table | Some more data |
Some data in a table | Some more data |
Some data in a table | Some more data |
Some data in a table | Some more data |
Some data in a table | Some more data |
Some data in a table | Some more data |
Some data in a table | Some more data |
Some data in a table | Some more data |
Some data in a table | Some more data |
Some data in a table | Some more data |
Some data in a table | Some more data |
Scrolling tables for wide tables
If you have a wide table that flows outside the screen area on smaller screens (when using responsive styles), you may want to make your table content scroll in place. To do this, you will need to add the class 'fullwidthscroll' to the parent <div>
of the table.
<div class="fullwidthscroll">
<table class="tbl-cell-bdr">
<tr>
<th>Heading 1</th>
<th>Heading 2</th>
<th>Heading 3</th>
</tr>
<tr>
<td>Some data in a table</td>
<td>Some more data</td>
<td>Some more datathatwontwrap...</td>
</tr>
<tr>
<td>Some data in a table</td>
<td>Some more data</td>
<td>Some more data</td>
</tr>
</table>
</div>
scroll sideways below for more content...
Heading 1 | Heading 2 | Heading 3 |
---|---|---|
Some data in a table | Some more data | Some more datathatwontwrapandmakesthetabfhdjalkshfklajshfiuawehyfiabgkjhd;ajHFIHGBALKJ;FADSHFIUGEWAHFBVLADSGHFIUEWAkjdlfhkljdaslereallywidewhichisaproblemonsmallerscreens |
Some data in a table | Some more data | Some more data |
We've created multiple table classes to make formatting easier. Please note that tables should only be used to display tabular data and should not use to arrange blocks of text or images. When laying out text you should use the grid layouts, or box styles, or pull quotes.
Table tags & structure
Table below gives you a general idea of the HTML code structure for a table and its commonly-used tags.
Tag | Description |
---|---|
<table> | It defines a table. |
<tr> | It defines a row in a table. |
<th> | It defines a header cell in a table. |
<td> | It defines a cell in a table. |
<tbody> | It is used to group the body content in a table |
<caption> | It defines the table caption. |
<table>
<caption> ... </caption> //define your table caption here.
<tbody> //container for body content.
<tr> //1st row in your table - use this to define your table header cells.
<th> ... <th> //header cell
<th> ... <th> //header cell
...
</tr>
<tr> //2nd row in your table - start to enter your tabular data
<td> ... <td> //table cell - matach your number of td with th.
<td> ... <td> //table cell
...
</tr>
...
</tbody>
</table>
By default, a <table>
has a black outer border, no borders within, and a tinted shade of table headers.
For accessibility, all tables should have table header cells and captions. You can also customise table borders and shadings.
Overview
If you are using version 4 of the ANU web styles, your site will be responsive - it will change layout depending on the screen size of the user's device. For this reason, you should not set your table or column widths to pixel values.
You can use these percentage-based classes to control the width of individual columns. These classes allow the table columns to layout properly on all screen sizes. These classes should be used on <th>
level. To ensure the table is taking 100% width of its parent container, the sum of all column widths should be 100%.
Class name | Width | Description |
---|---|---|
.tbl10 | 10% | The column width will be 10% of its parent container. |
.tbl20 | 20% | The column width will be 20% of its parent container. |
.tbl25 | 25% | The column width will be 25% of its parent container. |
.tbl30 | 30% | The column width will be 30% of its parent container. |
.tbl33 | 33% | The column width will be 33% of its parent container. |
.tbl40 | 40% | The column width will be 40% of its parent container. |
.tbl50 | 50% | The column width will be 50% of its parent container. |
.tbl60 | 60% | The column width will be 60% of its parent container. |
.tbl67 | 67% | The column width will be 67% of its parent container. |
.tbl70 | 70% | The column width will be 70% of its parent container. |
.tbl75 | 75% | The column width will be 75% of its parent container. |
.tbl80 | 80% | The column width will be 80% of its parent container. |
.tbl90 | 90% | The column width will be 90% of its parent container. |
.tbl100 | 100% | The column width will be 100% of its parent container. |
Use the caption to provide a short descriptive title for your table. The <caption>
element should be declared right after the <table>
element. Only 1 caption per table.
<table>
<caption> ... </caption>
<tbody>
...
</tbody>
</table>
Customisation
Table borders
To create a table with borders only applied to the rows:
Head 1 | Head 2 |
---|---|
Cell 1 contents | Cell 2 contents |
Cell 3 contents | Cell 4 contents |
<table class="tbl-row-bdr">
To create a table with borders only applied to the columns:
Head 1 | Head 2 |
---|---|
Cell 1 contents | Cell 2 contents |
Cell 3 contents | Cell 4 contents |
<table class="tbl-col-bdr">
To create a table with borders around every cell:
Head 1 | Head 2 |
---|---|
Cell 1 contents | Cell 2 contents |
Cell 3 contents | Cell 4 contents |
<table class="tbl-cell-bdr">
To create a table with a border around the outside and extra space between the cells:
Head 1 | Head 2 |
---|---|
Cell 1 contents | Cell 2 contents |
Cell 3 contents | Cell 4 contents |
<table class="tbl-space">
You can also use .noborder
to remove the outer border.
Table shading
You can apply standard colour classes (.bg-black
, .bg-tint
, .bg-white
) to either:
- the entire
<table>
; - individual row:
<tr>
; or - individual cell:
<td>
But please note: header cell color is fixed, which is tint. This cannot be overwritten.
<table class="tbl-row-bdr bg-black">
Head 1 | Head 2 |
---|---|
Cell 1 contents | Cell 2 contents |
Cell 3 contents | Cell 4 contents |
<tr class="bg-tint">
Head 1 | Head 2 |
---|---|
Cell 1 contents | Cell 2 contents |
Cell 3 contents | Cell 4 contents |
Floating/Sticky table headers for long tables
If you have a long table that is likely to take up more than a 1-page scroll, you can use the following classes to make your table header sticky at the top - always visible.
- add the
.anu-long-area
to the<table>
- add the
.anu-sticky-header
to the first table row<tr>
, which stores the header cells.
Note: the sticky header will not work in Internet Explorer 7, but should work in more modern browsers.
<table class="tbl-cell-bdr anu-long-area">
<tr class="anu-sticky-header">
<th>Heading 1</th>
<th>Heading 2</th>
</tr>
<tr>
<td>Some data in a table</td>
<td>Some more data</td>
</tr>
<tr>
<td>Some data in a table</td>
<td>Some more data</td>
</tr>
...
</table>
Heading 1 | Heading 2 |
---|---|
Some data in a table | Some more data |
Some data in a table | Some more data |
Some data in a table | Some more data |
Some data in a table | Some more data |
Some data in a table | Some more data |
Some data in a table | Some more data |
Some data in a table | Some more data |
Some data in a table | Some more data |
Some data in a table | Some more data |
Some data in a table | Some more data |
Some data in a table | Some more data |
Some data in a table | Some more data |
Some data in a table | Some more data |
Some data in a table | Some more data |
Some data in a table | Some more data |
Some data in a table | Some more data |
Some data in a table | Some more data |
Some data in a table | Some more data |
Some data in a table | Some more data |
Some data in a table | Some more data |
Horizontal scroll wide tables
If you have a wide table that flows outside the screen area on smaller screens (when using responsive styles), you may want to make your table responsive as well. To do this, you will need to add the .fullwidthscroll
to the parent <div>
of the table.
<div class="fullwidthscroll">
<table class="tbl-cell-bdr">
<tr>
<th>Heading 1</th>
<th>Heading 2</th>
<th>Heading 3</th>
</tr>
<tr>
<td>Some data in a table</td>
<td>Some more data</td>
<td>Some more datathatwontwrap...</td>
</tr>
...
</table>
</div>
scroll sideways below for more content...
Heading 1 | Heading 2 | Heading 3 |
---|---|---|
Some data in a table | Some more data | Loremipsumdolorsitamet,consecteturadipiscingelit,seddoeiusmodtemporincididuntutlaboreetdoloremagnaaliqua. |
Some data in a table | Some more data | Some more data |
Coming soon: Border colors
Use cases
40% | 10% | 25% | 25% |
---|---|---|---|
- | - | - | - |
<table class="tbl-cell-bdr">
<tr>
<th class="tbl40">40%</th>
<th class="tbl10">10%</th>
<th class="tbl25">25%</th>
<th class="tbl25">25%</th>
</tr>
<tr>
<td>-</td>
<td>-</td>
<td>-</td>
<td>-</td>
</tr>
</table>
Heading 1 | Cell 1 contents |
---|---|
Heading 2 | Cell 2 contents |
<table>
<caption>Example table with row headers</caption>
<tbody><tr>
<th scope="row">Heading 1</th>
<td>Cell 1 contents</td>
</tr>
<tr>
<th scope="row">Heading 2</th>
<td>Cell 2 contents</td>
</tr>
</tbody>
</table>