37

Div is not showing multiple white spaces in between strings

For Example:

This string 'New Folder' I would like to be displayed as 'New     Folder'

KyleMit
  • 30,350
  • 66
  • 462
  • 664
deepu
  • 1,993
  • 6
  • 42
  • 64

4 Answers4

55

That is how html works. Whitespace is collapsed. Look at the way your question is displayed to see an example.

To work around this, wrap your text in a <pre> tag, or use &nbsp; instead of space characters


Or add white-space:pre to the CSS for the div.

Kristianmitk
  • 4,528
  • 5
  • 26
  • 46
Ray
  • 21,485
  • 5
  • 48
  • 64
  • yes - I was just coming back to the question to add that suggestion :) It doesn't work in IE 8 and earlier, though. – Ray May 27 '11 at 11:39
  • @anothershrubery - 牛逼! which means fantastic and awesome in chinese! – Courage May 03 '17 at 09:03
13

You could also use CSS to add styling like a <pre> tag. Use

  div#where-you-want-the-whitespace {
      white-space: pre;
  }
Mark A
  • 1,995
  • 4
  • 18
  • 26
6

Try:

white-space: pre-wrap;

This does 2 things that can help others:

  1. Keeps spaces as you want.
  2. Wraps text so that if it is too long it remains clean inside a container.
kintsukuroi
  • 1,332
  • 16
  • 15
0

Yes, this is happening in html, just like you enter and it show same....

You need either to use simple html => &nbsp, or <pre> tag.... Or you can also assign variable to a 'span' tag by some id... => *"span style='padding-left:20px'"*This line starts after some blank space at left "span"

@* because tag is not accepting here so thats why use,, "span" .

Imran Khan
  • 2,373
  • 2
  • 22
  • 35