Search code examples
htmlhtml-tablew3c-validationhtml-heading

Is it valid to put h3 (or any heading) inside td tags?


The question is asked for TH tags, but I couldn't find one for TD tags.

Can I put headings inside <td> tags?


Solution

  • thead is not h3, if you use h3 inside td element, it is absolutely fine, but if you use h3 as a direct child to tr is invalid.

    Inorder to use thead you can use it like this

    <table>
       <thead>
          <tr>
             <th>This is table head and not h3</th>
          </tr>
       </thead>
       <tfoot>
          <tr>
             <td>Foot Cell</td>
          </tr>
       </tfoot>
       <tbody>
           <tr>
              <td>
                 <h3>It's completely valid to put your h3 here</h3>
                 Table cell
                 <p>You can also use p tag here
               </td>
           </tr>
       </tbody>
    </table>
    

    But if you do it something like this, is invalid

    <table>
       <tr>
          <h3>It's invalid</h3>
          <td>This is a cell</td>
       </tr>
    </table>
    

    You can always check here whether your markup is valid or not.