How to get a tab character?

Html

Html Problem Overview


In HTML, there is no character for a tab, but I am confused as to why I can copy and paste one here: . (You can't see the full width of it, but if you click to edit my question, you will see the character.) If I can copy and paste a tab character, there should be a unicode equivalent that can be coded into html. I know it doesn't exist, but this is a mystery I've never been able to grasp.

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

Html Solutions


Solution 1 - Html

Sure there's an entity for tabs:

	

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

However, just like literal tabs (ones you type in to your text editor), all tab characters are treated as whitespace by HTML parsers and collapsed into a single space except those within a <pre> block, where literal tabs will be rendered as 8 spaces in a monospace font.

Solution 2 - Html

Try &emsp;

as per the docs :

> 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 equuivalent to two space > characters.

Docs link : https://www.w3.org/MarkUp/html3/specialchars.html

Solution 3 - Html

put it in between <pre></pre> tags then use this characters &#9;

it would not work without the <pre></pre> tags

Solution 4 - Html

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

Each tab can be converted to a sequence non-breaking spaces which require no wrapping.

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

This is not recommended for repeated/extensive use within a page. A div margin/padding approach would appear much cleaner.

Solution 5 - Html

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

Solution 6 - Html

Tab is [HT], or character number 9, in the unicode library.

Solution 7 - Html

As mentioned, for efficiency reasons sequential spaces are consolidated into one space the browser actually displays. Remember what the ML in HTML stand for. It's a Mark-up Language, designed to control how text is displayed.. not whitespace :p

Still, you can pretend the browser respects tabs since all the TAB does is prepend 4 spaces, and that's easy with CSS. either in line like ...

 <div style="padding-left:4.00em;">Indenented text </div>

Or as a regular class in a style sheet

.tabbed {padding-left:4.00em;}

Then the HTML might look like

<p>regular paragraph regular paragraph regular paragraph</p>
<p class="tabbed">Indented text Indented text Indented text</p>
<p>regular paragraph regular paragraph regular paragraph</p>

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
QuestionAbbey GraebnerView Question on Stackoverflow
Solution 1 - Htmljosh3736View Answer on Stackoverflow
Solution 2 - HtmlAbhishek GoelView Answer on Stackoverflow
Solution 3 - HtmlRaymundView Answer on Stackoverflow
Solution 4 - HtmlcrokusekView Answer on Stackoverflow
Solution 5 - HtmlGrayFaceView Answer on Stackoverflow
Solution 6 - HtmlDanReduxView Answer on Stackoverflow
Solution 7 - HtmlDuane LortieView Answer on Stackoverflow