What can I use to substitute    in HTML?

72,259

Solution 1

Margin and/or Padding. (css properties), like so:

<p style='padding-left : 10px'>Hello</p>

(It's worth noting that it's generally considered bad-practice to put an inline style like that; you typically declare a selector in an external css file and set the class/whatever appropriately.)

Solution 2

In CSS try:

white-space:nowrap;

Solution 3

In CSS, Add

pre{
  white-space: pre-wrap;
  white-space: -moz-pre-wrap !important;
  white-space: -pre-wrap;
  white-space: -o-pre-wrap;
}
<pre>
    is not ugly anymore
</pre>

Solution 4

I had this problem when I realised I will have empty tags. I didn't want to set a fixed height and it was to late to change the html. I wanted to add a space in the css, the substitute for &nbsp, so I added the space before the element, using :before (it needs to be specified via unicode).

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

Hope this solution helps someone. The solution with padding didn't work for my problem.

Solution 5

&#160; is alternative but it's also ugly

Beautiful solution is available in css.

If u need space at start of paragraph the u can use

p {text-indent: 10px; }

If u need spacing between word use like this

H2 { word-spacing: 3pt }

see here for more options http://www.hypergurl.com/csstutorial7.html

You can give these style to html by inline, external and from in-page(<head>....</head>)

Share:
72,259
Steven
Author by

Steven

I'm a headhunter based in Hangzhou, China. I recruit software engineers, language experts, C-suite talents for companies. If you need my headhunting services, you can contact me via steven.tu[at]mipfanyi.com(Please replace "[at]" with "@"). If you want to get a job, you can also send a resume to my email.

Updated on April 28, 2021

Comments

  • Steven
    Steven about 3 years

    &nbsp;&nbsp; is ugly, I think.

  • Michael Biermann
    Michael Biermann over 11 years
    Yes &#160; is also ugly, but it is tolerated by Windows Phone 8 (VS Express 2012 Phone), while &nbsp; leads to an error (which can be ignored but is always displayed).
  • Madalina Taina
    Madalina Taina almost 8 years
    Actually, this is not helpful always. I think if you need a &nbsp element is probably because you don't have content in <p></p>