This shouldn't be red. |
This document is well-formed and valid XHTML. Above is a table with a single cell. This page has a single style rule to give all tbody
elements a red background, but no tbody
tags are written in the source.
In HTML, tr
elements are always inside a row group, so if a tr
is written as a child of a table
, a tbody
element is automatically assumed. In XHTML, this is different: when a tr
is written as a child of a table
, it really is a child of it and there is no tbody
element.
Although this is a matter of the DTD rather than the general SGML rules, most major browsers still follow the HTML behavior when the document is sent as text/html
, even if there is an XHTML doctype.
To illustrate the difference in the document structure, this page has a style rule to give all tbody
elements a red background. When properly handled as XHTML, there is no tbody
element, so nothing will be made red.
The difference will also be noticed in scripting languages. When the page is parsed as XML, the tr
will be an immediate child of the table
, but when the page is parsed as HTML, there will be a tbody
in between.