How can I use the common \t escape character in html ? Is it possible?
I need a code that has the same function as the /t escape character
Adding Tab Space in HTML Unlike with HTML space, there is no particular HTML tab character you could use. You could technically use the 	 entity as the tab is character 9 in the ASCII. Unfortunately, HTML parsers will simply collapse it into a single space due to the whitespace collapse principle.
A Tab is a single character (known as "HT" or ASCII 0x09 or "\u0009" or "\t"). Often when that character is displayed, it is rendered as some ammount of blank area. It has traditionally been rendered as the equivalent of 8 SPACE characters.
The tab-size property specifies the width of a tab character. In HTML, the tab character is usually displayed as a single space-character, except for some elements, like <textarea> and <pre>, and the result of the tab-size property will only be visible for those elements.
You can enter the tab character (U+0009 CHARACTER TABULATION, commonly known as TAB or HT) using the character reference 	
. It is equivalent to the tab character as such. Thus, from the HTML viewpoint, there is no need to “escape” it using the character reference; but you may do so e.g. if your editing program does not let you enter the character conveniently.
On the other hand, the tab character is in most contexts equivalent to a normal space in HTML. It does not “tabulate”, it’s just a word space.
The tab character has, however, special handling in pre
elements and (although this not that well described in specifications) in textarea
and xmp
element (in the latter, character references cannot be used, only the tab character as such). This is described somewhat misleadingly in HTML specifications, e.g. in HTML 4.01: “[Inside the pre
element, ] the horizontal tab character (decimal 9 in [ISO10646] and [ISO88591] ) is usually interpreted by visual user agents as the smallest non-zero number of spaces necessary to line characters up along tab stops that are every 8 characters. We strongly discourage using horizontal tabs in preformatted text since it is common practice, when editing, to set the tab-spacing to other values, leading to misaligned documents.”
The warnings are unnecessary except as regards to the potential mismatch of tabbing in your authoring software and HTML rendering in browsers. The real reason for avoiding horizontal tab is that it a coarse and simplistic tool as compared with tables for presenting tabular material. And in displaying computer source programs, it is better to use just spaces inside pre
, since the default tab stops at every 8 characters are quite unsuitable for any normal code indentation style.
In addition, in CSS, you can specify white-space: pre
(or, with slightly more limited browser support, white-space: pre-wrap
) to make a normal HTML element, like div
or p
, rendered like pre
, so that all whitespace is preserved and horizontal tab has the “tabbing” effect.
In CSS Text Module Level 3 (Last Call working draft, i.e. proceeding towards maturity), there is also the tab-size
property, which can be used to set the distance between tab stops, e.g. tab-size: 3
. It’s supported by newest versions of most browsers, but not IE (not even IE 11).
would be a work around if you're only after the spacing.
HTML doesn't have escape characters (as it doesn't use escape-semantics for reserved characters, instead you use SGML entities: &
, <
, >
and "
).
SGML does not have a named-entity for the tab character as it exists in most character sets (i.e. 0x09
in ASCII and UTF-8), rendering it completely unnecessary (i.e. simply press the Tab key on your keyboard). If you're working with code that generates HTML (e.g. a server-side application, e.g. ASP.NET, PHP or Perl, then you might need to escape it then, but only because the server-side language demands it - it has nothing to do with HTML, like so:
echo "<pre>\t\tTABS!\t\t</pre>";
But, you can use SGML entities to represent any ISO-8859-1 character by hexadecimal value, e.g. 	
for a tab character.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With