Is it good to put a &nbsp; inside an empty <td>?

Jitendra Vyas picture Jitendra Vyas · Mar 24, 2010 · Viewed 44.4k times · Source

If this is the structure:

<table cellspacing="0" cellpadding="0">
   <tr>
      <td>I don't need anything here, should I always put a &nbsp; here?</td>
      <td>item </td>
   </tr>
   <tr>
      <td>model</td>
      <td>one</td>
   </tr>
   <tr>
      <td>model</td>
      <td>two</td>
   </tr>
   <tr>
      <td>model</td>
      <td>three</td>
   </tr>
</table>

How will a screen reader read a blank td? Is it semantically correct?

Answer

Boldewyn picture Boldewyn · Mar 24, 2010

Semantically correct IMHO would be to keep an empty cell really empty. However, I, too, fill empty cells with &nbsp;s for pragmatic reasons.

As for screen readers, I'll have to make an educated guess: Empty nodes will likely not be read, because HTML consists mostly of whitespace text nodes, which readers ignore, and I assume, that &nbsp; is collapsed to a simple space in reader applications (since non-breaking is a property of visual media).

For rendering visually, one could rely on the CSS table property empty-cells:

table {
    empty-cells: show;
}