Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are table headers only for the top row in html?

I always see the th tag only used in the first row of the table. Is there some specific reason why it can't be used to create 'left' headers along the leftmost column. Is this bad form, or is this ok.

Basically, a table with headings on the top row and the leftmost column, with the very top left square being empty.

e.g.

<table>
    <tr>
        <th><!--empty--></th>
        <th>Top 1</th>
        <th>Top 2</th></tr>
    <tr>
        <th>LeftHeader?</th>
        <td>data1</td>    
        <td>data2</td></tr>
</table>
like image 407
Bill Zimmerman Avatar asked May 01 '10 13:05

Bill Zimmerman


People also ask

What is table header in HTML?

<th>: The Table Header element. The <th> HTML element defines a cell as header of a group of table cells. The exact nature of this group is defined by the scope and headers attributes.

Where is the header row in a table?

A table header is a row at the top of a table used to label each column.

What is a table header row?

A table header row is the top row of a table that acts as a title for the type of information they will find in each column. It's common to manually bold the top row to signal this information visually, but it's important to mark table headers at the code level so the change is also structural.

How do I make a table header in HTML?

Table heading can be defined using <th> tag. This tag will be put to replace <td> tag, which is used to represent actual data cell. Normally you will put your top row as table heading as shown below, otherwise you can use <th> element in any row. Headings, which are defined in <th> tag are centered and bold by default.


1 Answers

That's valid, however, when using a <thead> it has to be the first row. This is valid:

<table>
    <thead>
        <tr>
            <td>0,0</td><td>1,0</td><td>2,0</td>
        </tr>
    </thead>
    <tr>
        <th>0,1</th><th>1,1</th><th>2,1</th>
    </tr>
</table>

But this is not:

<table>
    <tr>
        <td>0,0</td><td>1,0</td><td>2,0</td>
    </tr>
    <thead>
        <tr>
            <th>0,1</th><th>1,1</th><th>2,1</th>
        </tr>
    </thead>
</table>

It's invalid HTML and you can double check that with the w3C markup validation service though before you do you'll have to add a <!DOCTYPE> declaration and the rest of a valid HTML doc.

like image 117
Richard JP Le Guen Avatar answered Oct 22 '22 13:10

Richard JP Le Guen