{{Short description|Entity in digital text}} A '''tab character''' is a control character that encodes alignment instructions in text. Unlike a printable character, it does not represent content like a letter or a digit. Although multiple tab characters have been defined and used in the past, today the variation that is widely used is the horizontal tab (HT). The vertical tab (VT) and other more esoteric alignment control characters were used in the past and remain defined in modern character encodings although rarely used.

==Use==

===Programming=== The use of tabs is common for aligning blocks of source code although spaces are a common alternative so a space is always as wide as any letter or symbol.

Tabs have some benefits over spaces when used for alignment. Backspace deletes one indentation level which usually doesn't happen for spaces in most editors. The displayed size of a tab can be changed in the settings menu of almost every editor.

The most common approach is to use tabs for indentation levels and spaces for alignment as code is typically viewed with a monospaced font. A text editor feature called elastic tabstops<ref>{{cite web|url=http://nickgravgaard.com/elastic-tabstops/|title=Elastic tabstops - a better way to indent and align code|first=Nick|last=Gravgaard|website=nickgravgaard.com|access-date=23 March 2018}}</ref> makes tabs useful for alignment too by adjusting the width of each individual tab in a text using an algorithm and solves alignment issues that otherwise occur when programming with proportional fonts.

Disagreements between programmers about what size tabs are correct, and whether to use tabs at all, are common.<ref>{{Cite web|title=Tabs versus Spaces|url=https://www.jwz.org/doc/tabs-vs-spaces.html|access-date=2020-06-02|website=www.jwz.org}}</ref> Modern text editors often use heuristics to adapt to the existing content of a file, inserting tabs or spaces and using tab stop size based on the style of the file content.

===Printing=== Originally, printer mechanisms used mechanical tab stops to indicate where the tabs went. This was done horizontally with movable metal prongs in a row, and vertically with a loop of mylar or other tape the length of a page with holes punched in it to indicate the tab stops. These were manually set to match the pre-printed forms that were loaded into the printer. In practice, settable tab stops were rather quickly replaced with fixed tab stops, de facto standardized at every multiple of eight characters horizontally, and every six lines vertically. A printing program could send zero or more tabs to get to the closest tab stop above and left of where it wanted to print, then send line feeds and spaces to get to the final location. In this sense, a tab character provides for data compression, specifying multiple spaces or lines with a single character.

===Text formatting=== The tab character is often used in text to align the left-side of content vertically and in particular to indent paragraphs and lines by an equal amount. In a text editor a (horizontal) tab may be inserted into the content when the tab key is pressed although often the editor can be set up to insert spaces instead of a tab. A word processor supports indentation and tabular formatting, but may or may not use the tab character to encode the formatting.

Despite the fact that five characters were the typical paragraph indentation on typewriters, the horizontal tab size of eight evolved because as a power of two it was easier to calculate with the limited digital electronics available.{{citation needed|date=December 2023}} Using this size tab to indent code results in much white space on the left, so most text editors for code, such as IDEs, allow the size of the tab to be changed, and some (in particular on Windows) default to four instead of eight.

===Tab-separated values=== The tab-separated values (TSV) data format is often used for exporting and importing tabular data such a database or spreadsheet. Some word processors format pasted TSV data as a table without requiring the user to indicate that they want a table.

Gopher menus use TSV to indicate selectors.

==Representation==

===ASCII=== In ASCII, the code has value 9. Since ASCII values were originally typed by holding the <kbd>Control</kbd> key and pressing a letter key on a typewriter-style terminal, the tab character is sometimes written as {{key press |Ctrl |I}} or {{mono|^I}}.

===EBCDIC=== In EBCDIC, the code for HT is 5. VT is 11 (the same as in ASCII).

===String literal escape syntax=== In many programming languages, the escape sequence {{code|\t}} represents the tab character in a string literal.

===Unicode=== The Unicode code points for the (horizontal) tab character, and the more rarely used vertical tab character are copied from ASCII:<ref>{{cite web| title = C0 Controls and Basic Latin | url = https://www.unicode.org/charts/PDF/U0000.pdf| access-date = 2013-12-13}}</ref>

* <big>{{unichar|0009|CHARACTER TABULATION}}</big> (CHARACTER TABULATION, horizontal tabulation (HT), tab) * <big>{{unichar|000B|LINE TABULATION}}</big> (LINE TABULATION, vertical tabulation (VT))

The tab characters can be graphically represented by special symbols: * <big>{{unichar|2409|SYMBOL FOR HORIZONTAL TABULATION}}</big> * <big>{{unichar|240B|SYMBOL FOR VERTICAL TABULATION}}</big>

Unicode also has characters for the symbols to represent or be printed on the tab key:<ref name="Unicode Arrows">{{cite web| title = Arrows – Unicode| url = https://www.unicode.org/charts/PDF/U2190.pdf| access-date = 2013-12-13}}</ref>

* <big>{{unichar|21B9|LEFTWARDS ARROW TO BAR OVER RIGHTWARDS ARROW TO BAR}}</big> (tab with shift tab) * <big>{{unichar|21C6|LEFTWARDS ARROW OVER RIGHTWARDS ARROW}}</big> * <big>{{unichar|21E4|LEFTWARDS ARROW TO BAR}}</big> (leftward tab) * <big>{{unichar|21E5|RIGHTWARDS ARROW TO BAR}}</big> (rightward tab)

Unicode provides additional characters for tab symbols with triangle-headed arrow:<ref name="Unicode Miscellaneous Symbols and Arrows">{{cite web| title = Miscellaneous Symbols and Arrows – Unicode| url = https://www.unicode.org/charts/PDF/U2B00.pdf| access-date = 2023-08-31}}</ref>

* <big>{{unichar|2B70|LEFTWARDS TRIANGLE-HEADED ARROW TO BAR}}</big> (left tab) * <big>{{unichar|2B71|UPWARDS TRIANGLE-HEADED ARROW TO BAR}}</big> (up tab) * <big>{{unichar|2B72|RIGHTWARDS TRIANGLE-HEADED ARROW TO BAR}}</big> (right tab) * <big>{{unichar|2B73|DOWNWARDS TRIANGLE-HEADED ARROW TO BAR}}</big> (down tab) * <big>{{unichar|2B7E|HORIZONTAL TAB KEY}}</big> * <big>{{unichar|2B7F|VERTICAL TAB KEY}}</big>

===HTML=== In HTML the horizontal tab is coded using {{code|&#9;}} or {{code|&Tab;}}<ref>See Character encodings in HTML#HTML character references</ref><ref name="W3CCharacterRef">{{cite web|url=http://dev.w3.org/html5/html-author/charref|title=Character Entity Reference Chart|website=dev.w3.org|access-date=23 March 2018}}</ref> but as with all whitespace characters in HTML, this will be displayed as a single space except inside {{tag|pre|open}}, {{tag|code|open}} tags (or other elements with CSS attribute {{code|white-space}} set to {{code|pre}}).

Here is an example:

<blockquote> ;HTML: <syntaxhighlight lang="html"> &Tab;This line begins with a single tab. Here&Tab;are&Tab;some&Tab;more&Tab;tab&Tab;characters&Tab;! T.......T.......T.......T.......T.......T.......T.......T </syntaxhighlight> ;Inside {{tag|pre|open}}: {{not a typo|<pre> &Tab;This line begins with a single tab. Here&Tab;are&Tab;some&Tab;more&Tab;tab&Tab;characters&Tab;! T.......T.......T.......T.......T.......T.......T.......T </pre>}} ;Outside {{tag|pre|open}}: <div style="font-family: monospace, monospace;"> {{not a typo|&Tab;This line begins with a single tab.}} {{not a typo|Here&Tab;are&Tab;some&Tab;more&Tab;tab&Tab;characters&Tab;!}} T.......T.......T.......T.......T.......T.......T.......T </div></blockquote>

Notice that the tab at the start of a line is removed outside {{tag|pre|open}}, the eight-character spacing, and how a tab stop is skipped if there are more than eight characters since last one.

CSS3 defines {{code|tab-size}} property, which adjusts the number of spaces for the tab character from the default of eight.<ref>{{cite web|url=http://dev.w3.org/csswg/css3-text/#tab-size-property|title=CSS 3 tab-size property W3 specification}}</ref> The latest version of WebKit supports the {{code|tab-size}} property. The Opera web browser supports the {{code|-o-tab-size}} CSS property, the Firefox web browser supports the {{code|-moz-tab-size}} CSS property with the same meaning.<ref>{{cite web|url=https://developer.mozilla.org/en-US/docs/CSS/tab-size|title=CSS tab-size property on Mozilla Developer Network|date=21 February 2023 }}</ref>

The vertical tab is {{code|&#xB;}} but is not allowed in SGML{{Citation needed|date=March 2013}}; this includes XML 1.0<ref>{{cite web|title=Extensible Markup Language (XML) 1.0|edition=5th|publisher=W3C|date=26 November 2008|url=https://www.w3.org/TR/xml/#charsets|at=sec. "Charsets"}}</ref> and HTML.

== See also == * {{Annotated link |Comma-separated values}}

== References == <references/>

Category:Control characters