__FORCETOC__
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:
Many computer languages use block indentation to demarcate blocks of source code.
Indention 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.
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.
See also: Indentation style.
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.
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.[1] These variations are driven by factors that may include but are not limited to: language syntax, organizational mandate and personal preference.
The following table identifies notable practices with respect to code indentation.
Language | Free-form? | Note | |
---|---|---|---|
Fritz Mehner's style guide suggests 2, 4, or 8 spaces and uses 2 in all examples[2] | |||
The Linux kernel uses 1 tab[4] [5]
Clinton Staley advocates 3 spaces[7] | |||
WebKit recommends 4 spaces[8] Google uses 2 spaces[9] | |||
Microsoft convention: 4 spaces[10] | |||
Drupal, GitHub, and Google use 2 spaces[11] [12] [13] [14] | |||
dart format uses 2 spaces | |||
Delphi style guide: 2 spaces [16] | |||
F# style guide: 4 spaces[17] | |||
Effective Go: 1 tab [18] | |||
Google uses 2 spaces[19] | |||
Google uses 2 spaces | |||
Oracle uses 4 spaces[21]
Most Eclipse IDE components use tabs | |||
Douglas Crockford advocates 4 spaces[23] GitHub and Google use 2 spaces[24] [25] Firefox's built-in jsbeautifier defaults to 2 spaces prettyprinter in Google Chrome and Internet Explorer use 4 spaces | |||
Julia | Julia style guide: 4 spaces[27] | ||
Kotlin | Kotlin style guide: 4 spaces[28] | ||
Lua style guide: 2 spaces[29] | |||
Larry Wall prefers 4 spaces[30] | |||
Drupal use 2 spaces[31] PEAR and Zend use 4 spaces[32] [33] CodeIgniter and WordPress use tabs[34] [35] PSR-2 specifies 4 spaces[36] | |||
Unofficial PowerShell Best Practices and Style Guide: 4 spaces[37] | |||
PEP 8: 4 spaces[38] | |||
Ruby style guide: 2 spaces [39] | |||
Rust style guide: 4 spaces [40] | |||
Scala style guide: 2 spaces [41] | |||
Google uses 2 spaces[42] | |||
Tcl style guide: 4 spaces [43] | |||
Microsoft convention: 4 spaces [44] | |||
Google uses 2 spaces[45] |
In 2006, a new method of indentation was proposed, called elastic tabstops.