Is it wrong to use more than one thead, tbody or tfoot in a table?

11

I have a table that gets a certain formatting when the elements have a tbody . Because of this formatting, I thought about using tbody twice in the same table, but I was wondering if that would be valid.

So, I would like to ask this question: Can I use more than tbody , tfoot or thead in the same table?

For example:

<table class="table">
     <thead>
           <tr>
              <td colspan=2>
                 <h1>Título</h1>
             </td>
            </tr>
     </thead>
     <thead>
         <tr>
             <th>ID</th>
             <th>Nome</th>
         </tr>
     </thead>
    <tbody>
      <tr>
          <td>1</td>
          <td>Wallace</td>
      </tr>
    </tbody>
</table>

In the above example, would it be invalid to use two thead ?

    
asked by anonymous 06.01.2017 / 12:22

3 answers

10

<tbody> can yes, but <thead> and <tfoot> no is allowed by specifying HTML5 (the same was true for HTML4 ).

  

In this order: optionally a caption element, followed by zero or more colgroup elements, followed optionally by a thead element, followed optionally by a tfoot element, followed by zero or more tbody elements or one or more tr elements, optionally followed by a tfoot element (but there can only be one tfoot element child in total), optionally intermixed with one or more script-supporting elements.

Emphasis is on what's important. The specification is very clear when it leaves have more than one. When he uses article to in English it means one , not even one.

Possible Solutions

You can join these two <thead> , there seems to be no reason to be separate, it can have more than one line.

It could be if there were clusters, but there is a main table that contains several bodies and inside the bodies have other tables for each group, there in each of these secondary tables you can have the header and footer. You can nest as many tables as you like, at various levels.

You may also want to use <caption> to add some information in the table.

    
06.01.2017 / 12:34
12

According to the DTD :

<!ELEMENT table
     (caption?, (col*|colgroup*), thead?, tfoot?, (tbody+|tr+))>
<!ELEMENT caption  %Inline;>
<!ELEMENT thead    (tr)+>
<!ELEMENT tfoot    (tr)+>
<!ELEMENT tbody    (tr)+>
<!ELEMENT colgroup (col)*>
<!ELEMENT col      EMPTY>
<!ELEMENT tr       (th|td)+>
<!ELEMENT th       %Flow;>
<!ELEMENT td       %Flow;>

(thead?) Aceito 0 ou 1 ocorrêcia

(tfoot?) Idem a anterior

(tbody+|tr+) Aceito 1 ou mais ocorrências

    
06.01.2017 / 12:41
7

Using more than thead and tfoot are not allowed. According to HTML specification :

  

In this order: optionally a caption element, followed by zero or more   colgroup elements, followed by a thead element, followed by   either zero or more tbody elements or one or more tr elements,   followed by a tfoot element, optionally intermixed with one   or more script-supporting elements.

That is:

In this order: optionally a caption element, followed by zero or more colgroup , optionally followed by one element thead , followed by zero or more elements tbody or one or more tr elements, optionally followed by a tfoot element, optionally mixed with one or more script support elements.

    
06.01.2017 / 12:33