Several tab characters are included as ASCII control characters, used for text alignment. The most known and common tab is a horizontal tab (HT), which in ASCII has the decimal character code of 9. A vertical tab (VT) also exists and has ASCII decimal character code 11. The EBCDIC code for HT is 5. The VT is 11 or hex 0B, the same as ASCII. The horizontal tab is usually generated by the tab key on a standard keyboard.
Originally printers 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. Initially these were manually set to match the preprinted forms the printer was going to print. The intention was to have the machine be programmed with other control characters to set and clear the stops but it is unclear if any popular printers implemented this. Instead it was rather quickly replaced with fixed tab stops, at every multiple of 8 characters horizontally and every 6 lines vertically, so they simply became a form of data compression, since a printing program could easily add the necessary spaces to move to any position wanted on a form. The vertical size was chosen to be 1 inch. It is unclear why the 8-character horizontal size was chosen, as 5 characters, half inch in a typical printer at that time, was much more popular at that time as a paragraph indentation. It may have been chosen to match early Fortran conventions for where the statement text started after the line number and continuation character. Or it may have been chosen as the smallest size that would fit numbers typically printed in a table.
ISO 6429 also includes the codes 136 Horizontal Tabulation Set, 137 Horizontal Tabulation with Justification and 138 Vertical Tabulation Set.
Tabs are almost always rendered as a form of whitespace larger than a single space, while some text editors mark tabs with special graphics to facilitate distinguishing tabs and whitespaces. In word processor applications, the tab key typically moves the cursor to the next tab stop. In most other graphical applications, the tab key will shift the focus to the next control or widget.
A UNIX program,
expand expands a tab to a number of spaces and
unexpand does the opposite.
Text divided into fields delimited by tabs can be pasted into a word processor and formatted into a table with a single command.
Here is an example showing the use of withtags. If you write in HTML:
The result would be something like this:
These 2 lines are tabbed: 2005 This line uses a tab space. This line also uses a tab space. This line does not use a Tab space.
... 2. All tabs (U+0009) are rendered as a horizontal shift that lines up the start edge of the next glyph with the next tab stop. Tab stops occur at points that are mutiples of 8 times the width of a space (U+0020) rendered in the block's font from the block's starting content edge.
Programmer's editors usually default to having the tab key generate hard tabs, i.e. horizontal tab (HT) characters, but some editors expand them to space (SP) characters instead, often referred to as soft tabs. Most programmer's editors can be configured to perform either.
There are many arguments for and against using hard tabs in code.
Those who favor spaces-as-indents argue that incompatibility and conversion issues ensue when the tab key generates HT characters and the editor is configured for tab stops spaced anything but the standard that was used in the original editor.
Those in favor of tabs argue the opposite, that tabs increase compatibility. Because hard-tab is a single character, indentation width is simply displayed at the programmer's preferred width. Code can be transported between programmers without the need to come to an agreement on tab width.
One problem frequently cited is the use of tabs to format text after non-whitespace characters have been used in a line. Such formatting will usually result in uneven ("jagged") display on an editor in which tab-width is different that in the original editor. Tabs-as-indents proponents do not advocate tabs for such formatting, urging the use of spaces instead. The confusion on this point is a frequent source of disagreement on the issue.
Another common problem is the mixed use of spaces and tabs in a project. Proponents of both spaces-as-indents and tabs-as-indents agree on this point: the usage should be consistent. Mixing tabs and spaces for indents is considered bad form.
One early benefit of tabs, that they saved space over using spaces, is now considered less relevant as desktop storage has become cheaper and sophisticated compression algorithms can provide much greater benefits, albeit at the cost of greater complexity.
Linus Torvalds has remarked that "Tabs are 8 characters, and thus indentations are also 8 characters. There are heretic movements that try to make indentations 4 (or even 2!) characters deep, and that is akin to trying to define the value of PI to be 3.