216

Possible ways:

<pre> ... </pre>

or

style="white-space:pre"

Anything else?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Yeseanul
  • 2,787
  • 4
  • 21
  • 25
  • Do you mean "tags" or "tabs"? – user123444555621 Mar 20 '12 at 23:53
  • 1
    [White space in HTML](http://webdesign.about.com/od/styleproperties/p/blspwhitespace.htm), [Tabs in HTML](http://webdesign.about.com/od/intermediatetutorials/qt/tiphtmltab.htm), [Spacing Out Your HTML](http://webdesign.about.com/od/beginningtutorials/a/aabg101399a.htm), and of course ` ` – benedict_w Mar 20 '12 at 18:40
  • 3
    Is there an equivalent to ` ` but to make a tab? – Juan Solano Jan 29 '16 at 15:35
  • There's no `&tab;`, but I did find this little js snippet on github (basically find and replace to create five ` ` in a row)... https://gist.github.com/AustinDizzy/1231e82184bea35c42ad – dmgig Apr 26 '16 at 00:01

19 Answers19

168

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

&emsp; and &ensp;

Giri
  • 2,704
  • 2
  • 25
  • 27
128

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>
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Japol
  • 1,289
  • 1
  • 7
  • 3
65

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Halim Qarroum
  • 13,985
  • 4
  • 46
  • 71
50

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Abhishek Goel
  • 18,785
  • 11
  • 87
  • 65
33

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]

Vivek Budithi
  • 562
  • 4
  • 14
  • 1
      worked fine for the browsers that I tested, new and old versions of Chrome and Firefox.   worked on some but not all. – Al Martins Oct 01 '21 at 18:30
24

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>
Community
  • 1
  • 1
Ivar Harris
  • 259
  • 2
  • 2
  • 1
    This is a good answer. But I just would like to say that it would be better using CSS class instead of id (it means replacing `#tab` by `.tab` and `id="tab"` by `class="tab"`) because if we use it more than once in a same document, we may have undefined behaviors. See, for instance, [this question](https://stackoverflow.com/questions/5611963/can-multiple-different-html-elements-have-the-same-id-if-theyre-different-eleme). – Hilder Vitor Lima Pereira Jul 10 '17 at 09:38
  • 1
    This helped me today. Thank you so much. – justnisar Jun 14 '18 at 23:32
16
<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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
sammyukavi
  • 1,501
  • 2
  • 23
  • 51
9

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...

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Dan
  • 315
  • 2
  • 13
6

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

You can also use:

padding-left
padding-right
padding-top
padding-bottom
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Ron1925
  • 61
  • 1
  • 1
5

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
mastro
  • 51
  • 1
  • 2
4

Use the standard CSS tab-size. see browser compatibility

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>
MrSwed
  • 559
  • 8
  • 15
  • It would be helpful for all users if you add the info about browser compability. [**Caniuse page says that IE11 does not support `tab-size`**](https://caniuse.com/mdn-css_properties_tab-size_length). – Bharata May 23 '23 at 17:56
  • @Bharata, ok, I'll make the link more explicit – MrSwed May 25 '23 at 07:01
4

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

prasoon
  • 901
  • 8
  • 25
3

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 :)

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Amr Saber
  • 988
  • 10
  • 26
  • 3
    Tables should be used to represent tabular data, not for formatting. In the 90s tables where frequently used for formatting because of limitations in HTML and frustrations writing HTML with styles that worked consistently across browsers. Today it is considered to be an anti-pattern. – David Baucum Mar 28 '17 at 18:01
  • I see your point, It may be some old-school solution but I had his problem once and using tables worked perfect for me – Amr Saber Mar 30 '17 at 06:39
  • 1
    Yes, but you can use table styling (with modern CSS) without messing up the semantic meaning! display: table, etc. – Julix May 30 '17 at 19:38
  • Well, **tab** is an abbreviation of the word **tabulator**, which was basically a spring-mounted lever which advanced the mechanical typewriter's carriage a fixed amount of space, dividing it in precise columns... for making tables to align precisely! :-) Aye, that's what it was used for: "tabs" were designed to make "tables". So, doing the equivalent in HTML is not _quite_ "messing up" with semantics, but rather using _older_ semantics for something that we have forgotten in the modern world of computers, which have replaced mechanical typrewriters but still have similar functions & names... – Gwyneth Llewelyn Apr 12 '23 at 12:48
2

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
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
1

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).

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
1

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;
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
James Pac
  • 31
  • 5
1

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

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Roshan Yadav
  • 133
  • 1
  • 3
  • 14
0

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
}
-2

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

It may not display correctly on the rendered version of the answer, but you can copy & paste it from the Markdown source if you wish.

Gwyneth Llewelyn
  • 796
  • 1
  • 11
  • 27
James
  • 1
  • 1
    I think you need to phrase the answer more clearly. Do you mean copy and paste a space from somewhere ? i dont think that would work here. – smilyface May 15 '19 at 13:20
  • 1
    There is a TAB in the Markdown source, but not in the HTML output here (it is instead a single space). – Peter Mortensen Jul 27 '19 at 17:51