How do I replicate a \t tab space in HTML?
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.