E-mail List Archives

RE: Can I use TDs with IDs and headers, instead of TH

for

From: Jukka K. Korpela
Date: Mar 12, 2003 11:47PM


On Wed, 12 Mar 2003, Rachel wrote:

> I noticed this on W3C:
>
> TH is for headers, TD for data, but for cells acting
> as both use TD

Interesting - it had somehow escaped my attention. It only appears in a
comment in the DTD, which is a partial explanation. (And as far as I
can see, it's something that has not been mentioned anywhere else,
including the so-called HTML 3 table model or in HTML 3.2. Well, it's
present in the XHTML 1.0 DTD, but that's no surprise since it's just a
technically edited copy of the HTML 4 DTD. There' no DTD for the
XHTML 2.0 draft yet, but anyway its prose text doesn't contain a statement
about cells acting both as headers and as data.=

> So sounds like the concensus is, use TH where
> something is purely a heading and use TD where
> something is functioning both as a heading and as
> data. And you can use the header attribute in both
> tags.

Regarding consensus, I don't think I ever saw a discussion about this
before, and I have personally used TH in such situations. It's really
problematic what a "data cell" versus "header cell" is. In the broad
sense, everything is data. If we take the narrower view where "data
proper" is distinguished from "organizational data" or "metadata"
(e.g., verses from verse numbers, or amounts of cups of coffee from
the header saying literally "Cups of coffee"), and if we say that TD
is for the former and TH is for the latter, things look easy until we get
to data like the names of people, about which there is data in the table.
Surely the name is data too and not just explanation of data. But it's
also a header, in the sense that it's the item that you would normally
want to use as _key_ to the rest of the information. If you pick up a cell
from the table and ask someone to read it for you, then the relevant
content is the column as specified by the column header - and the row
as specified by the name cell. Yet, the paradigmatic coffee consumption
example uses TD for the names. This might reflect a decision to
recomment TD for combined header and data cells - or just lack of
sufficient analysis.

In particular, the SCOPE attribute is defined using the words
"- - the current header cell - -", apparently referring to the element
where the attribute appears. The syntax allows it for both TH and TD,
but this is presumably an oversight. So if I have, say, a large table of
statistical data, lots of numbers in several columns, about all the
countries, I cannot do what would appear most natural: make the country
name (or code) the header cell in its row, with scope="row", which would
- together with the column header cells - give sufficient information to
user agents to read the table meaningfully, and even to implement query-based
presentation (prompting for questions like "what is the population of
Belgium?"). Instead, I would need to use the headers attribute in each and
every cell. I know I can use programs to generate such markup, but it
would still be weird, since much more natural markup would be so close.

> Can you have a header AND an ID both in one TD tag?

I presume you mean the HEADERS attribute here.

You can use the ID attribute for almost any element, surely including any
TD element. Its use is not limited to making it possible to refer to a
cell via a HEADERS attribute, and it does _not_ indicate the cell as a
header cell. The ID attribute could be used e.g. just to make the element
a possible destination for a link, or for CSS purposes.

> In other words, can you say that a TD tag is serving as a
> heading (ID attribute) for other data cells, but its
> own data also belongs under a heading somewhere else
> in the table (header attribute)?
>
> Example:
> <td id="title" headers="stories">MyTitle</td><td
> headers="title g7 k9">Sept 23</td> ...

That would appear to be the natural if not required approach, when you use
HEADERS attributes for indicating the structure of a table. And this
applies independently of the TD vs. TH issue.

My main concern is to _avoid_ using HEADERS. In the SCOPE approach, such a
cell would have scope="row" and it would appear in a column where another
cell has scope="col", making it clear that it is a header cell which
itself has a header cell. But if we take the specs, including the comment
in the DTD, quite literally, we _must not_ use scope="row", since
that would require <th ...>MyTitle</th>, and the title is surely
"data proper", too.

--
Jukka "Yucca" Korpela, http://www.cs.tut.fi/~jkorpela/


----
To subscribe, unsubscribe, or view list archives,
visit http://www.webaim.org/discussion/