CSS: how to add white space before element's content?

Hugolpz picture Hugolpz · May 14, 2013 · Viewed 129.5k times · Source

None of the following code works :

p:before { content: " "; }
p:before { content: " "; }

How do I add white space before element's content ?

Note: I need to color the border-left and the margin-left for semantic use and use the space as colorless margin. :)

Answer

Hugolpz picture Hugolpz · May 14, 2013

You can use the unicode of a non breaking space :

p:before { content: "\00a0 "; }

See JSfiddle demo

[style improved by @Jason Sperske]