How to insert spaces/tabs in text using HTML/CSS

HtmlCssTabsSpacePre

Html Problem Overview


Possible ways:

<pre> ... </pre>

or

style="white-space:pre"

Anything else?

Html Solutions


Solution 1 - Html

To insert tab space between two words/sentences I usually use

&emsp; and &ensp;

Solution 2 - Html

In cases wherein the width/height of the space is beyond &nbsp; I usually use:

For horizontal spacer:

<span style="display:inline-block; width: YOURWIDTH;"></span>

For vertical spacer:

<span style="display:block; height: YOURHEIGHT;"></span>

Solution 3 - Html

You can use &nbsp; for spaces, &lt; for < (less than, entity number &#60;) and &gt; for > (greater than, entity number &#62;).

A complete list can be found at HTML Entities.

Solution 4 - Html

Try &emsp;.

As per the documentation at Special Characters:

> The character entities &ensp; and &emsp; denote an en space and an em > space respectively, where an en space is half the point size and an em > space is equal to the point size of the current font. For fixed pitch > fonts, the user agent can treat the en space as being equivalent to A > space character, and the em space as being equivalent to two space > characters.

Solution 5 - Html

Types of Spaces in HTML

Creates four spaces between the text- &emsp;

Creates two spaces between the text - &ensp;

Creates a regular space between the text - &nbsp;

creates a narrow space ( similar to regular space but slight difference - "&thinsp";

spacing between sentences - "</br>"

This link might help you. Check out [https://hea-www.harvard.edu/~fine/Tech/html-sentences.html]

Solution 6 - Html

I like to use this:

In your CSS:

.tab { 
       display:inline-block; 
       margin-left: 40px; 
}

In your HTML:

<p>Some Text <span class="tab">Tabbed Text</span></p>

Solution 7 - Html

<p style="text-indent: 5em;">
The first line of this paragraph will be indented about five characters, similar to a tabbed indent.
</p>

The first line of this paragraph will be indented about five characters, similar to a tabbed indent.

See How to Use HTML and CSS to Create Tabs and Spacing for more information.

Solution 8 - Html

Go a step further than @Ivar and style my own custom tag like so... For me 'tab' is easier to remember and type.

tab {
    display: inline-block;
    margin-left: 40px;
}

And the HTML implementation...

<p>Left side of the whitespace<tab>Right side of the whitespace</p>

Screenshot of this code sample

And my screenshot...

Solution 9 - Html

<span style="padding-left:68px;"></span>

You can also use:

padding-left
padding-right
padding-top
padding-bottom

Solution 10 - Html

Alternatively referred to as a fixed space or hard space, non-breaking space (NBSP) is used in programming and word processing to create a space in a line that cannot be broken by word wrap.

With HTML, &nbsp; allows you to create multiple spaces that are visible on a web page and not only in the source code.

Solution 11 - Html

If you're asking for tabs to align stuff in some lines, you can use <table>.

Putting each line in <tr> ... </tr>. And each element inside that line in <td> ... </td>. And of course you can always control the padding of each table cell to adjust the space between them.

This will make them aligned and they will look pretty nice :)

Solution 12 - Html

You can do through padding like <span style="padding-left: 20px;">, you can check more ways here at - blank space in html

Solution 13 - Html

Use the standard CSS tab-size.

To insert a tab symbol (if standard tab key, move cursor) press Alt + 0 + 0 + 9

.element {
    -moz-tab-size: 4;
    tab-size: 4;
}

My preferred:

*{-moz-tab-size: 1; tab-size: 1;}

Look at snippet or quick found example at tab-size.

.t1{
    -moz-tab-size: 1;
    tab-size: 1;
}
.t2{
    -moz-tab-size: 2;
    tab-size: 2;
}
.t4{
    -moz-tab-size: 4;
    tab-size: 4;
}
pre {border: 1px dotted;}

<h3>tab = {default} space</h3>
<pre>
	one tab text
		two tab text
</pre>

<h3>tab = 1 space</h3>
<pre class="t1">
	one tab text
		two tab text
</pre>

<h3>tab = 2 space</h3>
<pre class="t2">
	one tab text
		two tab text
</pre>

<h3>tab = 4 space</h3>
<pre class="t4">
	one tab text
		two tab text
</pre>

Solution 14 - Html

White space? Couldn't you just use padding? That is an idea. That is how you can add some "blank area" around your element. So you can use the following CSS tags:

padding: 5px;
padding-top: 5px;
padding-bottom: 5px;
padding-left: 5px;
padding-right: 5px;

Solution 15 - Html

You can use this code &#8287; to add a space in the HTML content. For tab space, use it 5 times or more.

Check an example here: https://www.w3schools.com/charsets/tryit.asp?deci=8287&ent=ThickSpace

Solution 16 - Html

This worked for me:

In my CSS I have:

tab0  { position:absolute;left:25px;  }
tab1  { position:absolute;left:50px;  }
tab2  { position:absolute;left:75px;  }
tab3  { position:absolute;left:100px; }
tab4  { position:absolute;left:125px; }
tab5  { position:absolute;left:150px; }
tab6  { position:absolute;left:175px; }
tab7  { position:absolute;left:200px; }
tab8  { position:absolute;left:225px; }
tab9  { position:absolute;left:250px; }
tab10 { position:absolute;left:275px; }

Then in the HTML I just use my tabs:

Dog Food <tab3> :$30
Milk <tab3> :$3
Pizza Kit <tab3> :$5
Mt Dew <tab3> :$1.75

Solution 17 - Html

user8657661's answer is closest to my needs (of lining things up across several lines). However, I couldn't get the example code to work as provided, but I needed to change it as follows:

<html>
    <head>
        <style>
            .tab9 {position:absolute;left:150px; }
        </style>
    </head>

    <body>
        Dog Food: <span class="tab9"> $30</span><br/>
        Milk of Magnesia:<span class="tab9"> $30</span><br/>
        Pizza Kit:<span class="tab9"> $5</span><br/>
        Mt Dew <span class="tab9"> $1.75</span><br/>
    </body>
</html>

If you need right-aligned numbers you can change left:150px to right:150px, but you'll need to alter the number based on the width of the screen (as written the numbers would be 150 pixels from the right edge of the screen).

Solution 18 - Html

in my case I needed to insert at the beginning of each paragraph, so I did the following and it worked for me, I hope it can help someone

p:first-letter {
	margin-left: 20px
}

Solution 19 - Html

Here is a "Tab" text (copy and paste): " "

It may appear different or not a full tab because of the answer limitations of this site.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionYeseanulView Question on Stackoverflow
Solution 1 - HtmlGiriView Answer on Stackoverflow
Solution 2 - HtmlJapolView Answer on Stackoverflow
Solution 3 - HtmlHalim QarroumView Answer on Stackoverflow
Solution 4 - HtmlAbhishek GoelView Answer on Stackoverflow
Solution 5 - HtmlVivek BudithiView Answer on Stackoverflow
Solution 6 - HtmlIvar HarrisView Answer on Stackoverflow
Solution 7 - HtmlsammyukaviView Answer on Stackoverflow
Solution 8 - HtmlDanView Answer on Stackoverflow
Solution 9 - HtmlRon1925View Answer on Stackoverflow
Solution 10 - HtmlmastroView Answer on Stackoverflow
Solution 11 - HtmlAmr SaberView Answer on Stackoverflow
Solution 12 - HtmlprasoonView Answer on Stackoverflow
Solution 13 - HtmlMrSwedView Answer on Stackoverflow
Solution 14 - HtmlJames PacView Answer on Stackoverflow
Solution 15 - HtmlRoshan YadavView Answer on Stackoverflow
Solution 16 - Htmluser8657661View Answer on Stackoverflow
Solution 17 - HtmlSteve McRobertsView Answer on Stackoverflow
Solution 18 - HtmlFernando_AkistapaceView Answer on Stackoverflow
Solution 19 - HtmlJamesView Answer on Stackoverflow