htmlvalidationdatagridhtml-tablew3c

HTML5 validity of nested tables


I'm looking for the specs of HTML5 in terms of tables. I'm doing a web application has a lot of data tables.

These tables generally have one database row mapped to one table row. All is good. However one particular problem child has so many columns that it needs to be spread over two rows in the table. So the ordinary tables are (in pseudo):

<table>
<thead>
<tr>
  <th>Header</th>
</tr>
</thead>
<tbody>
<tr>
  <td>Data</td>
</tr>
</tbody>
</table>

And the problematic row are like this:

<table>
<tbody>
<tr>
  <th>Header row 1</th>
</tr>
<tr>
  <td>Data</td>
</tr>
<tr>
  <th>Header row 2</th>
</tr>
<tr>
  <td>Data</td>
</tr>
</tbody>
</table>

So my question is now: Is it valid to have nested tables in HTML5? We can easily agree that it's very ugly. But I'm considering only validity here.

If I can have nested tables, it will solve any number of problems pertaining to sorting and editing of these tables (have a semi data-grid functionality implemented). That way the main table can still consist of just one row with two columns. the sortable date and the embedded table with the data.

What do you say? I've been looking for the specs but couldn't find anything definite.


Solution

  • This document, which contains nothing but a nested table:

    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8">
        <title>A nested table</title>
    </head>
    <body>
        <table>
            <tbody>
                <tr>
                    <td>
                        <table>
                            <tbody>
                                <tr>
                                    <td>Nested</td>
                                    <td>Table</td>
                                </tr>
                            </tbody>
                        </table>
                    </td>
                </tr>
            </tbody>
        </table>
    </body>
    </html>
    

    …is valid, according to http://validator.w3.org/nu/:

    The document validates according to the specified schema(s) and to additional constraints checked by the validator.