How to get a tab character?

There is no tab character in HTML, but I'm confused about why I can copy and paste it here :. (You don’t see its full width, but if you click to change your question, you will see a character.) If I can copy and paste a tab character, there must be an unicode equivalent that can be encoded in html, I know this is not exists, but this is a secret that I could never understand.

So my question is: why is there no unicode character for the tab, even if I can copy and paste it?

+62
html
Mar 12 2018-12-12T00:
source share
6 answers

I am sure that the entity for tabs:

	 

(The tab is an ASCII 9 character or Unicode U + 0009.)

However, like literal tabs (those that you enter in your text editor), all tabs are treated as whitespace characters by HTML parsers and collapsed into one space , except for those located in the <pre> block where literal tabs will be displayed like 8 spaces in a monospace font.

+88
Mar 12 2018-12-12T00:
source share

put it between the <pre></pre> tags, then use these characters &#9;

it will not work without <pre></pre> tags

+32
Mar 12 2018-12-12T00:
source share

Try &emsp;

according to the documents:

Character objects &ensp; and &emsp; denote the space en and em space, where en-space is equal to half the size of the point and em space is equal to the size of the current font. For a fixed tone fonts, the user agent can treat the space en as equivalent to an A space character, and the em space is equal to the equivalent of two spaces characters.

Link to documents: https://www.w3.org/MarkUp/html3/specialchars.html

+17
May 05 '16 at 7:35
source share

Sending another alternative to be more complete. When I tried the answers based on "pre", they added extra vertical line breaks.

Each tab can be converted to a sequence without interruption, which does not require wrapping.

 "&nbsp;&nbsp;&nbsp;&nbsp;" 

This is not recommended for reuse on the page. The div / padding approach will be much cleaner.

+10
Oct 20 '14 at 22:19
source share

The unicode library contains the [HT] tab or character number 9.

+3
Mar 12 2018-12-12T00:
source share

I use <span style="display: inline-block; width: 2ch;">&#9;</span> for tabs two characters wide.

+3
May 7, '17 at 13:29
source share



All Articles