Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 209
Michael Sørensen Avatar asked Apr 24 '12 12:04

Michael Sørensen


People also ask

How many levels can HTML tables be nested?

You can create nested tables to any number of levels; just remember to create an inner table inside the same cell. Below is an interpretation of nested tables.

Can HTML tables be nested?

HTML supports this functionality and is known as the nesting of the tables. Tables can be nested together to create a table inside a table. To create a nested table, we need to create a table using the <table> tag.

Is it possible to use a table inside another table?

You cannot have a table inside another table at the back end.


1 Answers

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.

like image 170
Olly Hodgson Avatar answered Sep 21 '22 04:09

Olly Hodgson