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 thoughts on “Dev Tip: Preserve whitespace in HTML without using (nbsp)”

  1. 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!!

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s