31

Which is more semantic and valid?

<td> 
<p>
 content text
</p>
</td>

or

<td> 
 content text
</td>
Asaph
  • 159,146
  • 25
  • 197
  • 199
Jitendra Vyas
  • 148,487
  • 229
  • 573
  • 852

6 Answers6

47

Leave out the <p> tag unless the content of your table cell is truly a paragraph. It's certainly possible to have paragraphs in tabular data, and in that case a semantic <p> would be appropriately placed. But for the common table with data in the cells eg. numbers, names, etc., don't include the <p>.

Asaph
  • 159,146
  • 25
  • 197
  • 199
10

It depends on your intention. If the cell is going to have just ONE paragraph then it makes no sense to add the <p> tag to it.

If you intend to have a few paragraphs in the <td> cell then it makes sense to use the <p> tag.

Asaph
  • 159,146
  • 25
  • 197
  • 199
netrox
  • 5,224
  • 14
  • 46
  • 60
  • 4
    Why couldn't a single paragraph in a table cell be as semantically sensible as more than one? – micahwittman Dec 22 '09 at 04:52
  • 1
    A practical issue one may also run into is having to handle CSS declarations for single paragraph sections of markup and multiple paragraphs differently (because

    is present in one case and not the other). Not a huge deal, but worth noting.

    – micahwittman Dec 22 '09 at 05:22
  • 1
    Like I said, it all depends on your intention. I actually vote for Asaph's reply as he explains better than I do! – netrox Dec 22 '09 at 08:49
3

They are both valid. However, if you are going to have multiple paragraphs, obviously use the <p> tags

Asaph
  • 159,146
  • 25
  • 197
  • 199
WarmWaffles
  • 531
  • 5
  • 16
1

If the tabular cell data is text:

<td> 
 content text
</td>

If the tabular cell data is paragraph(s):

<td> 
<p>
 content text
</p>
...
</td>
micahwittman
  • 12,356
  • 2
  • 32
  • 37
0

Both are valid; if that is the only content of <td>, and the content is not being used in JavaScript code, then the second is better.

apaderno
  • 28,547
  • 16
  • 75
  • 90
0

Depends on if you subscribe to the "tables are for tabular data" or the "tables are for layout" school. If you prefer to use your tables for tabular data, and the paragraph is not tabular data the "p" is valid, if tables are for layout, and you have the "p" tag reserved for other layout semantics then its not required.

Short answer is, its really up to you. :)

GrayWizardx
  • 19,561
  • 2
  • 30
  • 43