is it necessary to have <th>
in any table? even if table has no heading?
table has 3 other tag <thead>
<tbody>
<tfoot>
is it necessary to use all even if i have nothing for table footer. Firefox by default add all these in code.
and is it necessary , <th>
always should be in a <thead>
and if I have a heading in content received from client , and heading is from outside the table but related to table then how should i place that heading for table
As a above table
<h3>Heading of table<h3>
<table>......</table>
as a heading of table
<table>
<thead><tr rowspan=3><th>Heading of table</th></tr></thead>
or as a caption of table
<table>
<caption> Heading of table</caption>
Which is good for screen reader and semantically correct?
Use
<th>
s if you are displaying tabular data - use one for each column. It is nice for your regular users and essential for screen readers. Do not use<th>
s if you are using the table for layout purposes (or other nefarious schemes...)No, it is not necessary to have th. But it doesn't look like you're using th right. Generally, you have one for each column. A simple example of th used correctly is:
You could also do:
You want to use what describes your data best.
<caption>
will describe the whole table.th
will create a single cell which is usually used to describe one column (but can also be used for row headings).thead
,tfoot
, andtbody
. all can be used and are all optional provided that they are in that order, if used, and you have only onethead
and onetfoot
(but you can have multipletbody
. Many browsers (all?) will add them implicitly if you don't, but the spec says they're optional.th
can appear inside anytr
regardless of where thetr
is.This is minimum table that I can think of.
The answer is
YES!
if you are using tables to display tabular data.
Tabular data are organized into rows and columns for a reason. The meaning of the datum in a table cell is defined by the meaning of the column and the row in which it appears.
It is important to identify those cells that give meaning to the rows and columns rather separately from the cells that just contain data.
For example, the following table conveys absolutely no meaningful information:
The numbers only have meaning if the rows and columns are given names. Those names are marked up using
<th>
:Of course, we still do not know what those numbers mean which is why
<caption>
is needed:Finally, it is important to note details such as the units of measurement, data sources etc. That kind of information usually goes in the footer of the table:
The title of the table goes into
<caption>
. The<thead>
and<tfoot>
sections are especially useful when a table grows large. See How to deal with page breaks when printing a large HTML table for an example.You can use
<colgroups>
to group together logically related data.The benefits are semantics. The
<th>
means T able H eader. Use it to markup the headers of your columns. Generally within a<thead>
.