24

Here is a fiddle demonstrating the problem

http://jsfiddle.net/WM8XW/

I have inserted many whitespace in the content of the label tag but the html rendered seems to remove it. Is adding   only solution to the above problem

HTML Content

<label>label with very          long white space in between</label>
Deeptechtons
  • 10,945
  • 27
  • 96
  • 178

3 Answers3

59

The normal behavior for the display of whitespaces is to compress them into a single one, which is then displayed.

There are two exceptions from that:

  1. The <pre> tag, which keeps the whitespaces as entered.
  2. Setting the CSS property white-space: pre; (respectively pre-wrap or pre-line)
insertusernamehere
  • 23,204
  • 9
  • 87
  • 126
Sirko
  • 72,589
  • 19
  • 149
  • 183
7

Browsers usually treat multiple consecutive spaces and/or carriage returns as a single space. In the case of non-breaking spaces (&nbsp; or &#160;) browsers will typically honor multiple consecutive occurrences as-is with no collapsing to a single space.

Solution1:

You can hard code the (&nbsp; or &#160;) as much as you want.

Reference

Any text between the opening <pre> tag and the closing </pre> tag will preserve the formatting of the source document.

Solution2: You can make use of <pre> tag.

Reference

If you want to execute with css also you can perform the same the above answers are only from html point of view

2

Yes multiple white spaces are converted to one white space by browser. Your only option is to have hard space ie. &nbsp;

bansi
  • 55,591
  • 6
  • 41
  • 52