Correct html markup for table tags?

Some kind of stupid question, but I saw things like tbody and / tfoot tags in other peoples tables.

Are they required, even if they are empty for good layout? Or can I just leave them?

+4
source share
6 answers

Table sections (thead / tbody / tfoot) are optional. The table heading (caption) and columns (col / colgroup) are also optional.

In HTML (but not XHTML), the closing tag for rows and cells is also optional, so you can write a table as:

<table> <tr> <th>1 <th>2 <tr> <td>3 <td>4 <tr> <td>5 <td>6 </table> 

However, it is recommended that you close tags to get a better structure in your code. It also makes things easier if you decide to switch to XHTML.

+3
source

They are not required, but they allow you to do more advanced things with headers and footers: http://www.htmldog.com/guides/htmladvanced/tables/

+2
source

Those tags are not required, and the page will check even without them.

+2
source

If you really need tables, you should use them. If you use tables for design purposes only, you should switch to css markup.

A simple example of a valid table:

 <table> <thead> <tr> <td>id</td> <td>name</td> </tr> </thead> <tbody> <tr> <td>1</td> <td>User1</td> </tr> <tr> <td>2</td> <td>User2</td> </tr> </tbody> </table> 
0
source

Yes, this is the correct markup. Although they are optional, you can read further on the W3Schools page.

0
source

The <tbody> is only partially supported in all major browsers.
Tables can have multiple bodies, but when it has only one body, the HTML tbody tag can be safely omitted.

0
source

Source: https://habr.com/ru/post/1313182/


All Articles