Indentation (typesetting)
In the written form of many languages, an indentation or indent is an empty space at the beginning of a line to signal the start of a new paragraph. Many computer languages have adopted this technique to designate "paragraphs" or other logical blocks in the program.
For example, the following lines are indented, using between one and six spaces:
This paragraph is indented by 1 space.
This paragraph is indented by 3 spaces.
This paragraph is indented by 6 spaces.
In computer programming, the neologisms outdent, unindent and dedent are used to describe the reversal of the indentation process, realigning text with the page margin.
In right-to-left languages, indentation is used just the same, but from the right margin of the paper, where the line begins.
Indentation in typesetting
There are three main types of indentation, illustrated below in relation to borders representing the page dimensions.Indentation in programming
In computer programming languages, indentation is used to format program source code to improve readability. Indentation is generally only of use to programmers; compilers and interpreters rarely care how much whitespace is present in between programming statements. However, certain programming languages rely on the use of indentation to demarcate programming structure, often using a variation of the off-side rule. The Haskell, Occam, Python, and Ya programming languages rely on indentation in this way.Debates over where to indent, whether to use spaces or tabs, and how many spaces to use are often hotly debated among programmers, leading some to classify indentation as akin to a religious war. In 2006 a third method of indentation was proposed, called elastic tabstops.
In addition to general indentation of statements, different bracket indentation styles are commonly used.
Language | Indent | Note |
Bash | varies | Fritz Mehner's Style Guide suggests 2, 4, or 8 spaces and uses 2 in all examples. Google uses 2 spaces. |
C | varies | The Linux kernel uses 1 tab. NASA uses 4 spaces. |
C++ | varies | Google uses 2 spaces. |
C# | 4 spaces | Per Microsoft's C# Coding Conventions. |
CSS | varies | Drupal, GitHub, and Google use 2 spaces. WordPress uses tabs. |
Delphi | 2 spaces | Default in RAD Studio. |
Go | 1 tab | Per "Effective Go". |
Haskell | varies | Google uses 2 spaces. |
HTML | varies | Google uses 2 spaces. HTML Tidy defaults to 2 spaces. |
Java | varies | Oracle uses 4 spaces. Android uses 4 spaces. Most Eclipse IDE components use tabs. |
JavaScript | varies | Douglas Crockford advocates 4 spaces. GitHub and Google uses 2 spaces. jQuery uses tabs. Firefox's built-in jsbeautifier defaults to 2 spaces. The built-in prettyprinter in Google Chrome and Internet Explorer uses 4 spaces. |
Kotlin | 4 spaces | Per Kotlin style guide. |
Lua | 2 spaces | Per Lua Style Guide. |
Perl | 4 spaces | Per "perlstyle: Perl style guide". |
PHP | varies | Drupal use 2 spaces. PEAR and Zend use 4 spaces. CodeIgniter and WordPress uses tabs. PSR-2 specifies 4 spaces. |
Python | 4 spaces | Per PEP-8. |
Ruby | 2 spaces | Per Ruby Style Guide. |
Rust | 4 spaces | Per Rust Style Guide. |
Scala | 2 spaces | Per Scala style guide. |
Tcl | 4 spaces | Per Tcl style guide. |
Visual Basic | 4 spaces | Per Microsoft's Visual Basic Coding Conventions. |