Customize tables
There are now utility classes available to customize the look and feel of your tables. You can add borders and background stripes to row or columns; align cell content, to the top, bottom or middle of the cell; and an alternate swipe experience.
For these customizations, you will edit the source HTML directly. Learn about editing source code.
Note: By default, the table layout is responsive to the user's screen-size and will fold into a two column layout with headers on the left for viewport that is 640px or less. This may cause some utility classes to be idle in mobile view. *Resize your viewport to across the 40em (640px) breakpoint to see the responsive table style live.
Steps for adding classes:
These are the general steps for using utility classes to customize tables.
- Create your table as outlined in the Tables page.
- Confirm that you have column and possibly row headers. Headers are required for these utility classes to work.
- Click the Source button. (Learn about editing source code.)
- For a table class, add the class to the
<table>
tag
i.e.,<table class="su-table-striped-rows-odd">
- For a table cell, add the class to all the
<td>
tags.
i.e.,<td class="vertical-align-top">
Borders
To add borders to all the rows and/or columns in your table, use the following classes in your <table>
tag
class="vertical-border"
class="horizontal-border"
class="vertical-border horizontal-border"
Example: Horizontal border
Year | USA | CHN | RUS |
---|---|---|---|
2012 | 104 | 88 | 82 |
2008 | 110 | 100 | 72 |
2004 | 103 | 62 | 92 |
Example: Vertical border
Year | USA | CHN | RUS |
---|---|---|---|
2012 | 104 | 88 | 82 |
2008 | 110 | 100 | 72 |
2004 | 103 | 62 | 92 |
Example: Vertical and Horizontal border
Year | USA | CHN | RUS |
---|---|---|---|
2012 | 104 | 88 | 82 |
2008 | 110 | 100 | 72 |
2004 | 103 | 62 | 92 |
Striped Rows and Columns:
To add row or column stripes, use the following classes in your <table>
tag.
class="su-table-striped-rows-odd"
class="su-table-striped-cols-odd"
class="su-table-striped-rows-even"
class="su-table-striped-cols-even"
Example: Striped Odd Rows
Year | USA | CHN | RUS |
---|---|---|---|
2012 | 104 | 88 | 82 |
2008 | 110 | 100 | 72 |
2004 | 103 | 62 | 92 |
Example: Striped Odd Columns
Year | USA | CHN | RUS |
---|---|---|---|
2012 | 104 | 88 | 82 |
2008 | 110 | 100 | 72 |
2004 | 103 | 62 | 92 |
Align Content
By default, content is vertically aligned in the middle of a table cell. To change that alignment, use the following classes on the <td>
tag.
class="vertical-align-top"
class="vertical-align-bottom"
Example: Cell content align top
Year | USA | CHN | RUS |
---|---|---|---|
2012 | 104 U.S. athletes left London with a total of 46 gold, 28 silver and 30 bronze. | 88 | 82 |
2008 | 110 | 100 | 72 |
2004 | 103 | 62 | 92 |
Example: Cell content align bottom
Year | USA | CHN | RUS |
---|---|---|---|
2012 | 104 U.S. athletes left London with a total of 46 gold, 28 silver and 30 bronze. | 88 | 82 |
2008 | 110 | 100 | 72 |
2004 | 103 | 62 | 92 |
Add a "swipe" experience
By default in smaller viewports, tables will break into rows. The "swipe" experience changes that; it maintains the table layout and uses multiple displays for column data. This allows for direct manipulation of the table on your user's screen. The content of the table isn't compromised when a user adjusts their browser window. To add the swipe experience use the tablesaw-swipe
class in your <table>
tag.
class="tablesaw-swipe"
Example: Swipe experience in a smaller viewport
At smaller viewport sizes the table will be broken into multiple displays. For example, with smaller viewport size, the first through forth columns of the table display first. Clicking on the next column button displays the second through fifth columns.
Try the Swipe experience
To see this change live, resize your viewport to across the 40em (640px) breakpoint.
Movie Title | Rank | Year | Rating | Gross |
---|---|---|---|---|
Avatar | 1 | 2009 | 83% | $2.7B |
Titanic | 2 | 1997 | 88% | $2.1B |
The Avengers | 3 | 2012 | 92% | $1.5B |
Harry Potter and the Deathly Hallows—Part 2 | 4 | 2011 | 96% | $1.3B |
Frozen | 5 | 2013 | 89% | $1.2B |
Iron Man 3 | 6 | 2013 | 78% | $1.2B |
Transformers: Dark of the Moon | 7 | 2011 | 36% | $1.1B |
The Lord of the Rings: The Return of the King | 8 | 2003 | 95% | $1.1B |
Skyfall | 9 | 2012 | 92% | $1.1B |
Transformers: Age of Extinction | 10 | 2014 | 18% | $1.0B |
Troubleshooting
Utility classes are not working
If the utility classes are not working, check that your table is built with column headers. Without the column headers, these utility classes will not work.
Learn more about editing tables