# Indentation (typesetting)

In the written form of many languages, indentation describes empty space, a.k.a. white space, used around text to signify an important aspect of the text such as:
* Beginning of a paragraph
* Hierarchy – subordinate concept
* Quotation
Many computer languages use block indentation to demarcate blocks of source code.
Indentation is essentially the same regardless of whether the writing system is left-to-right (e.g. Latin and Cyrillic) or right-to-left (e.g. Hebrew and Arabic) when considering line beginning and end. For example, indenting at the beginning of line means on the left for a left-to-right script and on the right for right-to-left script.
Indent is both a noun and a verb. The verb is the act of formatting text to be indented whereas the noun refers to the resulting empty space.

## Types

There are three main types of indentation: first-line, hanging and block.
Each example below is in a box that represents the page boundary and uses the common typesetting lorem ipsum content. The width of indentation here is in units of em spaces.

### For first-line indentation the first line of a paragraph is indented, U+2029 PARAGRAPH SEPARATOR

    A first-line indentation of 2 em: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

### For hanging indentation all but the first line of a paragraph is indented.

    A hanging indentation of 2 em: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

### For block indentation the entire paragraph is indented relative to the preceding paragraph.

    A block indentation of 2 em on the left: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
    Block indentation on both sides is commonly used for a quotation, a block quotation, here shown with 2 em on the left and right but since it is not right-aligned, the empty space on the right varies based on line length: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
    Here's the same as the previous but justified (left and right aligned): Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

## Indentation in programming

In computer programming, indentation describes formatting source code with whitespace to the left of code text – often to visually show that a sequence of code lines is syntactically a code block. Typically, the lines of a block are aligned with an amount of white space that indicates the block's depth in the hierarchical structure of the code. Each inner level of the hierarchy is indented by a multiple of this indentation width.
White space in code is typically stored as whitespace characters.
For a free-form language, indentation is exclusively for the programmer since a code processor (i.e. compiler, interpreter) ignores whitespace characters. Code can have inconsistent or even no indentation, but in general is formatted with somewhat consistent indentation.
Some languages rely on indentation to demarcate block structure, often via the off-side rule. Due to this syntax requirement, the code must have a level of consistency that is not required in free-form language code.
The neologisms outdent, unindent and dedent describe the opposite of indentation – aligning code text of a line to the left of the previous line.

### Variations

Common variations in the implementation of indentation include: how much to indent a block at each level of the code hierarchy, usually measured in spaces, and whether to store whitespace characters as space or tab characters. Although there are common practices, consensus is not universal.
These variations are driven by factors that may include but are not limited to: language syntax, organizational mandate and personal preference.

### Common practices

The following table identifies notable practices with respect to code indentation.
| Language | Free-form? | Note |
| Bash | Yes | Fritz Mehner's style guide suggests 2, 4, or 8 spaces and uses 2 in all examples Google uses 2 spaces |
| C | Yes | The Linux kernel uses 1 tab NASA uses 4 spaces. Clinton Staley advocates 3 spaces |
| C++ | Yes | WebKit recommends 4 spaces Google uses 2 spaces |
| C# | Yes | Microsoft convention: 4 spaces |
| CSS | Yes | Drupal, GitHub, and Google use 2 spaces WordPress uses tabs |
| Dart | Yes | dart format uses 2 spaces |
| Delphi | Yes | Delphi style guide: 2 spaces |
| F# | Yes | F# style guide: 4 spaces |
| Go | Yes | Effective Go: 1 tab |
| Haskell | No | Google uses 2 spaces |
| HTML | Yes | Google uses 2 spaces HTML Tidy defaults to 2 spaces |
| Java | Yes | Oracle uses 4 spaces Android uses 4 spaces Most Eclipse IDE components use tabs |
| JavaScript | Yes | Douglas Crockford advocates 4 spaces GitHub and Google use 2 spaces jQuery uses tabs Firefox's built-in jsbeautifier defaults to 2 spaces prettyprinter in Google Chrome and Internet Explorer use 4 spaces |
| Julia | Yes | Julia style guide: 4 spaces |
| Kotlin | Yes | Kotlin style guide: 4 spaces |
| Lua | Yes | Lua style guide: 2 spaces |
| Perl | Yes | Larry Wall prefers 4 spaces |
| PHP | Yes | Drupal use 2 spaces PEAR and Zend use 4 spaces CodeIgniter and WordPress use tabs PSR-2 specifies 4 spaces |
| PowerShell | Yes | Unofficial PowerShell Best Practices and Style Guide: 4 spaces |
| Python | No | PEP 8: 4 spaces |
| Ruby | Yes | Ruby style guide: 2 spaces |
| Rust | Yes | Rust style guide: 4 spaces |
| Scala | Yes | Scala style guide: 2 spaces |
| Swift | Yes | Google uses 2 spaces |
| Tcl | Yes | Tcl style guide: 4 spaces |
| Visual Basic | Yes | Microsoft convention: 4 spaces |
| XML | Yes | Google uses 2 spaces |

### Elastic tabstops

In 2006, a new method of indentation was proposed, called elastic tabstops.