Search code examples
htmltagsw3c

W3C compliance br tags in table


I want the spacing in the UI to be exactly the same as the spacing in my modification. The original code was written as:

<table>
<tr>
<td>stuff</td>
</tr>
<br/>
<tr>
<td>stuff</td>
</tr>
</table>

This code gives a w3c error and is incorrect. I modified this code to:

<table>
<tr>
<td>stuff</td>
</tr>
<tr style="display:none;"><td><br/></td></tr>
<tr>
<td>stuff</td>
</tr>
</table>

This code is w3c compliant but I noticed that the spacing in the modification is completely different than the original code, which is not a desired result.

Does anyone know why this occurs and/or a way to fix this issue?


Solution

  • You are misusing the br element. It must only be used for meaningful line breaks that are part of the content (e.g., in addresses or in poems).

    You should use CSS instead.

    You might want to use your browser’s developer tools to inspect the applied CSS (probably coming from browser’s default stylesheets if there is no author-styling for the br element) of the original code, and try to reimplement it for the new code (targeting existing/valid elements).