tags:

views:

248

answers:

5

I need to generate spaces in a HTML file.

A: 

&nbsp; is a non-breaking space. Alternatively I guess you could use a <br /> (XHTML there) tag just to generate a new line.

James Brooks
I don't need a new line.
Steven
+11  A: 

Use either &nbsp or <pre> tags. The <pre> tag preserves all spaces, tabs and newlines.

EDIT
Regarding your comment about its use, for padding, you may want to look at css padding

Yacoby
+1, `<pre>` will preserve all whitespace.
Richard Nguyen
+1 for css padding
Drevak
+1  A: 

I hardly ever use &nbsp;

margin and padding properties work well for spacing and <br /> for newlines. (I don't use <br /> too frequently either.)

Nimbuz
+4  A: 

It all depends on the context, you can use letter-spacing, word-spacing or for example padding for surrounding span's.

Without more information it´s impossible to give a good advice.

Edit: if it´s for use in texts / in between words, I´d go for the word-spacing and perhaps letter-spacing.

jeroen
word-spacing is very good. Thank you, @jeroen.
Steven
just to add a tidbit, 1em is equal to 1 font heigth so 2em is the same space as 2 font of the current setting (context) which scales size with the text then.
Mark Schultheiss
A: 

Yacoby is right. But i have something different:

<head>

<style type="text/css">
.left-space{ margin-left: 10px }
</style>

</head>

<body>

<div>
   <p>This is a test line.<span class="left-space">This is a line with space before it.</span></p>
</div>

</body>

And by the way you should replace   with   to conform to XHTML.

Colour Blend