siva kumar
siva kumar

Reputation: 139

How to use " " in HTML5

In HTML using   for space, I get one space in the output. If my requirement needs more spaces say 100, then how to make that tag efficient? Should I type   100 times?

Upvotes: 13

Views: 134535

Answers (4)

Lakshay Rohilla
Lakshay Rohilla

Reputation: 2728

&nbsp is a character entity that denotes a non-breaking or fixed space. It`s used to create a space that will not break into a new line by word wrap. Provide space the same as a regular space.

Correct syntax :   (must add a semi-colon at the end) is a character entity for a non-breaking space.

You can use it either inside the container tag or just after closing the tag:

<!--Inside container tag-->
<p>Text&nbsp;Text</p>
<!--After closing the tag-->
<button class="btn btn-primary">Start Game</button> &nbsp;
<button class="btn btn-danger">End Game</button>

This will provide one space between the buttons.enter image description here

Without &nbsp; enter image description here

We can use tons of &nbsp; :
for instance - <p>Text&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Text</p>

But we have a tag provided in HTML itself named as <pre></pre>
Using this we could have as much required space as we want between the text.
For instance:

<p>text&nbsp;&nbsp;text</p> //gives out 2 spaces.
<pre>text      text</pre>  //gives out the added spaces.

Upvotes: 1

srivenkat
srivenkat

Reputation: 11

you will use directly &nbsp; (or) &#160; for needed places. ex:

<img src="vj.jpg">&nbsp;<img src="ss.jpg">

the pictures displayed in sequence with space.

Upvotes: 1

user2473779
user2473779

Reputation: 731

As mentioned in the comments, you should be using css for this. However, if you have to do it in html, use 'pre' tags:

<pre>hello       world</pre>  //prints with extra spaces in between

Upvotes: 7

Vishal Kumar
Vishal Kumar

Reputation: 4627

&nbsp; is generally used when you are intended to place a space. It is generally used when you are considering the design in terms of space a letter occupies.

If you want to vary space depending upon other factors, feel free to use padding and margin.

Upvotes: 8

Related Questions