Question: I have to render some text to a web page. The text is coming from sources outside my control and it is formatted using newlines and tab characters.

New lines `(\n)` can be replaced by `br` tags, but what about preserving tabs? A brief search reveals there is no way to directly render tab characters in HTML.

Answer: 
replace `\t` with `&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;`.

Each space you want will be a `&nbsp;`

*As pointed out this isn't completely correct as it only pretends to be a tab as HTML doesn't actually output format a tab as you would expect.*
**`&emsp;`**, **`&ensp;`**, **`&#8195;`** or **`&#8194;`** can be used. 

W3 says little about this...

```
The character entities &ensp; and &emsp; denote an en space and an em space respectively, where an en space is half the point size and an em space is equal to the point size of the current font. 

```

[Read More at W3.org fro HTML3](http://www.w3.org/MarkUp/html3/specialchars.html)

[Read More at W3.org for HTML4](http://www.w3.org/TR/html4/sgml/entities.html)

Even more at [Wikipedia](http://en.wikipedia.org/wiki/Template_talk%3aSpace) (about spaces)