Which is more semantic and valid?
<td> <p> content text </p> </td>
or
<td> content text </td>
Complete HTML/CSS Course 2022 We can easily add HTML tag inside a table. The HTML tag should be placed inside the <td> tag. For example, adding a paragraph <p>… </p> tag or other available tags inside the <td> tag.
If it's paragraph of text then you should use p tag, so I would recommend to replace div to p in order to be semantically correct and help search engines better understand your content. The same way it goes for headings: if there is heading then you should use proper tag (h1 to h6 tag).
The <td> tag can contain text, form, image, table etc. The content inside it is left-aligned by default. If you present tabular data in tables than each data cell must be added individually as a <td> element.
In HTML it's important to understand that P elements cannot contain other block level elements and TABLE is a block level element.
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>
.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With