From Surf Wiki (app.surf) — the open knowledge base
Indentation (typesetting)
Empty space at the beginning of a line to signal the start of a new paragraph
Empty space at the beginning of a line to signal the start of a new paragraph
FORCETOC 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:
- 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,
A first-line indentation of 2 em: hanging indent For hanging indentation all but the first line of a paragraph is indented.
A hanging indentation of 2 em: block indent For block indentation the entire paragraph is indented relative to the preceding paragraph.
A block indentation of 2 em on the left: 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: Here's the same as the previous but justified (left and right aligned):
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 | Fritz Mehner's style guide suggests 2, 4, or 8 spaces and uses 2 in all examples | |
| C | The Linux kernel uses 1 tab | |
| [C++](c) | WebKit recommends 4 spaces | |
| C# | Microsoft convention: 4 spaces | |
| CSS | Drupal, GitHub, and Google use 2 spaces | |
| Dart | `dart format` uses 2 spaces | |
| Delphi | Delphi style guide: 2 spaces | |
| F# | F# style guide: 4 spaces | |
| Go | *Effective Go*: 1 tab | |
| Haskell | Google uses 2 spaces | |
| HTML | Google uses 2 spaces | |
| Java | Oracle uses 4 spaces | |
| JavaScript | Douglas Crockford advocates 4 spaces | |
| Julia | Julia style guide: 4 spaces | |
| Kotlin | Kotlin style guide: 4 spaces | |
| Lua | Lua style guide: 2 spaces | |
| Perl | Larry Wall prefers 4 spaces | |
| PHP | Drupal use 2 spaces | |
| PowerShell | Unofficial PowerShell Best Practices and Style Guide: 4 spaces | |
| Python | PEP 8: 4 spaces | |
| Ruby | Ruby style guide: 2 spaces | |
| Rust | Rust style guide: 4 spaces | |
| Scala | Scala style guide: 2 spaces | |
| Swift | Google uses 2 spaces | |
| Tcl | Tcl style guide: 4 spaces | |
| Visual Basic | Microsoft convention: 4 spaces | |
| XML | Google uses 2 spaces |
Elastic tabstops
In 2006, a new method of indentation was proposed, called elastic tabstops.{{cite web |access-date = 2025-12-03 |archive-url = https://web.archive.org/web/20060719102209/http://nickgravgaard.com/elastictabstops/ |archive-date = 2006-07-19 |access-date = 2025-12-03 | access-date = 2025-12-03 | access-date = 2025-12-03
References
References
- (2007-01-05). "Tabs versus Spaces: An Eternal Holy War".
- "Bash Style Guide and Coding Standard".
- "Archived copy".
- "Archived copy".
- (August 1994). "C STYLE GUIDE".
- Staley, Clinton. (2006). "C Program Style Rules".
- (2015-11-07). "Code Style Guidelines".
- [http://google-styleguide.googlecode.com/svn/trunk/cppguide.html#Spaces_vs._Tabs] {{webarchive. link. (2014-10-06)
- Bill Wagner. "C# Coding Conventions (C# Programming Guide)".
- (14 January 2013). "CSS formatting guidelines".
- "CSS · Styleguide · GitHub".
- "Google HTML/CSS Style Guide". Google GitHub.
- (3 September 2017). "styleguide: Style guides for Google-originated open-source projects".
- (17 July 2012). "WordPress › CSS Coding Standards « Make WordPress Core".
- "Delphi's Object Pascal Style Guide - White Space Usage".
- "F# code formatting guidelines".
- "Effective Go – The Go Programming Language".
- (2014-01-08). "HaskellStyleGuide – ganeti – Style Guide for the Haskell code – Cluster-based virtualization management software – Google Project Hosting".
- (2008-06-18). "HTML Tidy Configuration Options Quick Reference".
- "Code Conventions for the Java Programming Language: 4. Indentation".
- "Code Style Guidelines for Contributors | Android Developers".
- (2006-11-13). "Code Conventions for the JavaScript Programming Language".
- "JavaScript 路 Styleguide".
- "JaveScript Style Rules".
- jQuery Foundation - jquery.org. "JavaScript Style Guide | Contribute to jQuery".
- "Style Guide · The Julia Language".
- "Coding Conventions – Kotlin Programming Language".
- "lua-users wiki: Lua Style Guide".
- "perlstyle: Perl style guide". Perl Foundation.
- "Coding standards".
- "Manual :: Indenting and Line Length".
- "PHP Coding Standard (draft) – Contributors – Zend Framework Wiki".
- "Style Guide : CodeIgniter User Guide".
- (23 July 2012). "WordPress › PHP Coding Standards « Make WordPress Core".
- "PHP : Coding Style Guide".
- "Code Layout and Formatting – PowerShell Practice and Style".
- "PEP 8 – Style Guide for Python Code".
- Batsov, Bozhidar. (3 September 2017). "ruby-style-guide: A community-driven Ruby coding style guide".
- (3 September 2017). "rust: A safe, concurrent, practical language".
- "Indentation – Scala Documentation".
- "Swift Style Guide".
- Ray Johnson. "Tcl Style Guide".
- (4 January 2007). "Structured Coding Conventions".
- "Google XML Document Format Style Guide". Google.
This article was imported from Wikipedia and is available under the Creative Commons Attribution-ShareAlike 4.0 License. Content has been adapted to SurfDoc format. Original contributors can be found on the article history page.
Ask Mako anything about Indentation (typesetting) — get instant answers, deeper analysis, and related topics.
Research with MakoFree with your Surf account
Create a free account to save articles, ask Mako questions, and organize your research.
Sign up freeThis content may have been generated or modified by AI. CloudSurf Software LLC is not responsible for the accuracy, completeness, or reliability of AI-generated content. Always verify important information from primary sources.
Report