HTML Concepts: Indicators for Layout Tables

Published on September 13, 2021, filed under (RSS feed for all categories).

You use tables for data, and therefore not for layout purposes (as was popular in the past). But how would you recognize a layout table? That’s what we’re looking at today in “HTML Concepts.”

While it may be easy for you and me to tell when a table is used inappropriately, it’s a different story for a user agent. The HTML specification covers this problem in its section on the table element.

First, the spec notes how in order to navigate a table, user agents “are encouraged to find heuristics to determine which tables actually contain data and which are merely being used for layout.”

Then it offers a few heuristics, but not without making clear that these are not precise, how they are merely “suggested as possible indicators.” Keep this in mind when looking at what are deemed technical indicators for layout tables:

Code Characteristic(s) Interpretation
role attribute with a value of presentation Probably a layout table
border attribute with a value of 0 (non-conforming) Probably a layout table
cellspacing and cellpadding attributes with a value of 0 (non-conforming) Probably a layout table
caption, thead, or th elements Probably a non-layout table
headers and scope attributes Probably a non-layout table
border attribute (non-conforming) with a value other than 0 Probably a non-layout table
Visible borders set using CSS Probably a non-layout table
summary attribute Unclear, as “both layout and non-layout tables have historically been given this attribute”

While we can tell by its contents whether a table is used for layout, these are ways to tell from the code. Fortunately, layout tables are largely a thing from the past, and for a modern web developer, knowledge of technical layout table indicators is of little practical value. But—now you know.

Was this useful or interesting? Share (toot) this post, and support my work by learning with my ebooks!

About Me

Jens Oliver Meiert, on November 9, 2024.

I’m Jens (long: Jens Oliver Meiert), and I’m a frontend engineering leader and tech author/publisher. I’ve worked as a technical lead for companies like Google and as an engineering manager for companies like Miro, I’m a contributor to several web standards, and I write and review books for O’Reilly and Frontend Dogma.

I love trying things, not only in web development (and engineering management), but also in other areas like philosophy. Here on meiert.com I share some of my experiences and views. (Please be critical, interpret charitably, and give feedback.)