Dev Tip: Preserve whitespace in HTML without using (nbsp)


If you want to preserve whitespace within an HTML element (div/span) without using non-breaking spaces (and therefore breaking word-wrap), add the following property to the CSS style(s) for that element:

white-space:pre-wrap;

There are more options available for this property as well:

http://www.w3.org/TR/CSS2/text.html#white-space-prop

7 Comments

  1. ascorpio says:

    Cool! Saved my time.

  2. sagar says:

    Thanks. Really helped me good time.

  3. Frank says:

    Thanks! This is really helpful. At first I thought I had problems with ColdFusion not reading the spaces from the DB, then I thought it may have been the DB, when all along it was HTML rules!!

  4. Thanks. Really helpful. 🙂

  5. I love canon, I still get so much use out of my 1d classic

  6. Natalie Kurd says:

    This website said pre-wrap is not recognized by IE (http://www.htmldog.com/reference/cssproperties/white-space/). Unfortunately, I am working on IE. Any suggestion? Thanks.

    1. willwm says:

      Looks like this might help you out: http://stackoverflow.com/a/4413129

Leave a reply to Natalie Kurd Cancel reply