Template:Short description Template:Redirect Template:Use dmy dates Template:Sister project


In the written form of many languages, indentation describes empty space (white space) used before or around text to signify an important aspect of the text such as:

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.

TypesEdit

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.

Template:Glossary begin Template:Term Template:Defn Template:Term Template:Defn Template:Term Template:Defn Template:Defn Template:Defn Template:Glossary end

Indentation in programmingEdit

Template:See also

In computer programming, indentation describes formatting source code with whitespace to the left of code text Template:Endash 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 Template:Endash aligning code text of a line to the left of the previous line.

VariationsEdit

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. <ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref> These variations are driven by factors that may include but are not limited to: language syntax, organizational mandate and personal preference.

Common practicesEdit

The following table identifies notable practices with respect to code indentation.

Language Free-form? Note
Bash Template:Yes citation CitationClass=web

}}</ref>

Google uses 2 spaces <ref>{{#invoke:citation/CS1|citation

CitationClass=web

}} </ref>

C Template:Yes The Linux kernel uses 1 tab<ref>{{#invoke:citation/CS1|citation CitationClass=web

}} </ref><ref> {{#invoke:citation/CS1|citation

CitationClass=web

}} </ref>

NASA uses 4 spaces.<ref>{{#invoke:citation/CS1|citation

CitationClass=web

}}</ref>

Clinton Staley advocates 3 spaces<ref>{{#invoke:citation/CS1|citation

CitationClass=web

}}</ref>

C++ Template:Yes citation CitationClass=web

}}</ref> Google uses 2 spaces<ref>[1] Template:Webarchive</ref>

C# Template:Yes Microsoft convention: 4 spaces<ref>{{#invoke:citation/CS1|citation CitationClass=web

}}</ref>

CSS Template:Yes Drupal, GitHub, and Google use 2 spaces<ref>{{#invoke:citation/CS1|citation CitationClass=web

}}</ref><ref>{{#invoke:citation/CS1|citation

CitationClass=web

}}</ref><ref name="google">{{#invoke:citation/CS1|citation

CitationClass=web

}} This is an HTML-rendered copy of the official version, which is maintained in XML format</ref><ref>{{#invoke:citation/CS1|citation

CitationClass=web

}}</ref>

WordPress uses tabs<ref>{{#invoke:citation/CS1|citation

CitationClass=web

}}</ref>

Dart Template:Yes dart format uses 2 spaces
Delphi Template:Yes citation CitationClass=web

}}</ref>

F# Template:Yes citation CitationClass=web

}}</ref>

Go Template:Yes citation CitationClass=web

}}</ref>

Haskell Template:No citation CitationClass=web

}}</ref>

HTML Template:Yes Google uses 2 spaces<ref name="google" />

HTML Tidy defaults to 2 spaces<ref>{{#invoke:citation/CS1|citation

CitationClass=web

}}</ref>

Java Template:Yes Oracle uses 4 spaces<ref>{{#invoke:citation/CS1|citation CitationClass=web

}}</ref>

Android uses 4 spaces<ref>{{#invoke:citation/CS1|citation

CitationClass=web

}}</ref>

Most Eclipse IDE components use tabs

JavaScript Template:Yes Douglas Crockford advocates 4 spaces<ref>{{#invoke:citation/CS1|citation CitationClass=web

}}</ref>

GitHub and Google use 2 spaces<ref>{{#invoke:citation/CS1|citation

CitationClass=web

}}</ref><ref>{{#invoke:citation/CS1|citation

CitationClass=web

}}</ref>

jQuery uses tabs<ref>{{#invoke:citation/CS1|citation

CitationClass=web

}}</ref>

Firefox's built-in jsbeautifier defaults to 2 spaces

prettyprinter in Google Chrome and Internet Explorer use 4 spaces

Julia Template:Yes citation CitationClass=web

}}</ref>

Kotlin Template:Yes citation CitationClass=web

}}</ref>

Lua Template:Yes citation CitationClass=web

}}</ref>

Perl Template:Yes Larry Wall prefers 4 spaces<ref>{{#invoke:citation/CS1|citation CitationClass=web

}}</ref>

PHP Template:Yes Drupal use 2 spaces<ref>{{#invoke:citation/CS1|citation CitationClass=web

}}</ref>

PEAR and Zend use 4 spaces<ref>{{#invoke:citation/CS1|citation

CitationClass=web

}}</ref><ref>{{#invoke:citation/CS1|citation

CitationClass=web

}}</ref>

CodeIgniter and WordPress use tabs<ref>{{#invoke:citation/CS1|citation

CitationClass=web

}}</ref><ref>{{#invoke:citation/CS1|citation

CitationClass=web

}}</ref>

PSR-2 specifies 4 spaces<ref>{{#invoke:citation/CS1|citation

CitationClass=web

}}</ref>

PowerShell Template:Yes citation CitationClass=web

}}</ref>

Python Template:No citation CitationClass=web

}}</ref>

Ruby Template:Yes citation CitationClass=web

}}</ref>

Rust Template:Yes citation CitationClass=web

}}</ref>

Scala Template:Yes citation CitationClass=web

}}</ref>

Swift Template:Yes citation CitationClass=web

}}</ref>

Tcl Template:Yes citation CitationClass=web

}}</ref>

Visual Basic Template:Yes citation CitationClass=web

}}</ref>

XML Template:Yes citation CitationClass=web

}}</ref>

Elastic tabstopsEdit

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

ReferencesEdit

Template:Reflist

Template:Commons cat