Accessible data tables

Data tables may not be the most thrilling things ever produced in HTML, but they’re still one of the things most frequently fubared on the web today. There are a few subtle differences in the way HTML5 handles data tables, so it’s a good opportunity to take another look at this web page workhorse.

Quick data table recap: Data tables create relationships between pieces of information held in rows and columns. When you look at the table, those relationships are easy to understand because of the table’s layout and design. If you use a screen reader though, you’ll need another way to discover those relationships, and that (of course) is why the underlying HTML is so important.

First, the caption element. It hasn’t changed in HTML5 except that the align attribute has been deprecated. It’s used to provide a quick notation on the table’s content.

When a screen reader focuses on a table, the caption is read automatically. That makes it easy for a blind person to understand what the table contains. If an NVDA user used the t shortcut key to move to the table in example 1 (see downloadable file), they’d hear ‘Hot drink consumption statistics’.

The headers attribute is still present in HTML5, but it can now be applied to the th element as well as td. It creates an association between the header and the table cell.

The headers attribute takes the idref of the th and creates an association screen readers can use. The content of the th with the ID is announced by the screen reader, before the content of the th with the corresponding headers attribute. Moving across Alice’s row in the table in example 2, a reader user will hear “Tea 1 cup, Coffee 3 cups”.

The scope attribute has also undergone a slight change. It can no longer be applied to the td element in HTML5, only the th. It’s still used to define the range of cells that the th applies to. The table in example 3 demonstrates this.

Using the headers attribute on both the th and td elements is more time-consuming, but it is more bulletproof. Legacy screen readers tend not to play well with the scope attribute, so for the time being at least the header/id association is more robust.

Finally, the thead, tbody and tfoot (not shown here) elements are still available in HTML5. The difference is that none of their HTML4 attributes are supported. These elements are useful for long data tables because browsers can enable the tbody content to scroll, while leaving the thead and tfoot content visible.

It’s a misconception that tables ought to be avoided. We’ve thankfully moved past the days when tables were used for layout, but well structured and clearly designed data tables make it easy for screen reader users to access tabular data in a meaningful way.

Thank you for reading 5 articles this month* Join now for unlimited access

Enjoy your first month for just £1 / $1 / €1

*Read 5 free articles per month without a subscription

Join now for unlimited access

Try first month for just £1 / $1 / €1

TOPICS

The Creative Bloq team is made up of a group of design fans, and has changed and evolved since Creative Bloq began back in 2012. The current website team consists of eight full-time members of staff: Editor Georgia Coggan, Deputy Editor Rosie Hilder, Ecommerce Editor Beren Neale, Senior News Editor Daniel Piper, Editor, Digital Art and 3D Ian Dean, Tech Reviews Editor Erlingur Einarsson and Ecommerce Writer Beth Nicholls and Staff Writer Natalie Fear, as well as a roster of freelancers from around the world. The 3D World and ImagineFX magazine teams also pitch in, ensuring that content from 3D World and ImagineFX is represented on Creative Bloq. 

Latest in HTML
Write HTML faster
How to write HTML code faster
HTML tags
8 HTML tags you need to be using (and 5 to avoid)
HTML tags
HTML tags: A guide to the basics
18 great HTML APIs – and how to use them
Convert Flash games to HTML5
Convert Flash games to HTML5
Build a simple HTML page
Latest in How to
Rob Redman's snowy image illustrates the AE tutorial: TDW313.PT_AE_Snow.indd
How to create realistic snow with particle systems using After Effects
Ivan Mironenko ZBrush character tutorial
Craft a game-ready character asset using ZBrush and Substance 3D Painter
Oliver Schümann ZBrush bizarre baby tutorial
Create a bizarre baby sculpture in ZBrush
Alireza Khoshpayam arch-viz tips
Speedy tips to create beautifully photoreal archviz using 3ds Max and Corona
Maya 3D abstract strands tutorial
How to easily create complex and abstract animation using Maya
Whiskytree battle damage effects tutorial
Create gnarly battle damage for vehicles using a mix of Maya and Nuke