Michael Lee
Michael Lee

Reputation: 327

How to add space inside a div tag

Silly question but I was wondering if it is possible to add a large spacing inside my div text. For example,

<div>Hello                  there</div>

Would I have to modify it in css? Is there a way of doing it without css.

Upvotes: 1

Views: 7720

Answers (4)

Richard
Richard

Reputation: 7433

If you want to avoid CSS, you can use &nbsp; to force an extra space character, &ensp; for two spaces, and &emsp; for four spaces. However, I do not get why you seem uneager to use CSS to achieve this.

You usually use HTML to show the content (and its meaning). In this case, a lot of spaces aren't meaningful to your content. To change the appearance of your content, you should consider using CSS instead. That being said, as requested, here's how you add space without using CSS.

<div>Hello&nbsp;&nbsp;there</div>

<div>Hello&ensp;&ensp;there</div>

<div>Hello&emsp;&emsp;there</div>

Upvotes: 5

Mr Lister
Mr Lister

Reputation: 46559

I agree with the others that CSS is the way to go here. For example:

div {text-align:justify; text-align-last:justify;}
<div>hello there</div>

Or, with inline CSS rather than external:

<div style="text-align:justify; text-align-last:justify;">hello there</div>

But if it's impossible to use CSS, can you change your html? There are lots of ways of doing this with html. Example:

<table width="100%"><tr><td>hello</td><td align="right">there</td></tr></table>

Upvotes: 1

nourza
nourza

Reputation: 2321

You can add this &nbsp; in the html for space or margin-left and you can control the space of changing the number

span{
margin-left: 80px;
}
<div>Hello <span>there</span></div>

Upvotes: 0

Borislav Stefanov
Borislav Stefanov

Reputation: 731

You can insert a longer space by using any one of the following options:

Two spaces - Type &ensp;

Four spaces - Type &emsp

Indent - Type &nbsp;&nbsp;&nbsp;&nbsp

Upvotes: 0

Related Questions