View Full Version : Preserve White-space in <td>

11-18-2011, 11:19 AM
Hello PPL,

So i have a table , which shows list of files in a given folder.

Suppose a file contains multiple white-spaces e.x.
a b.txt a SPACE SPACE b.txt (i think even here the whitespace is getting trimmed)
inside a <td> of a table with NO styling or class applied, the white-space is getting trimmed into a sinlge space.

I tried <td style="white-space: pre"> but that is not working.

PRE tag works but only in ie8. not in firefox or safari.

Pls help.


11-18-2011, 11:52 AM
You have several possibilities. Let's take two of them:

1. use non-breaking space entity: &nbsp; for every white space. Not a recommended practice, but you may use it for 2-3 withe spaces, on need.

2. nest some substring within SPAN elements and use the CSS padding:

<td>a<span style="padding-left:10px">b</span></td>

11-18-2011, 12:10 PM
Is it the default behavior of all browsers to ignore the white-spaces.? I cannot replace the white-space with &nbsp; since the file name is retrieved on the fly from the database. So i needed some CSS or html solutions to preserve the white-space appearing in the file names.

11-18-2011, 12:51 PM
Then make some changes at the server-side level.