Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Indentation (typesetting)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|Empty space at the beginning of a line to signal the start of a new paragraph}} {{Redirect|Indentation}} {{Use dmy dates|date=July 2022}} {{Wiktionary|indentation}} __FORCETOC__ In the written form of many [[language]]s, '''indentation''' describes empty space ([[White space (visual arts)|white space]]) used before or around text to signify an important aspect of the text such as: * Beginning of a [[paragraph]] * [[Hierarchy]] {{endash}} subordinate concept * [[Quotation]] Many [[computer languages]] use ''block indentation'' to demarcate [[code block|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 (typography)|em]] spaces. {{glossary begin}} {{term|1=first-line indentation|style=font-weight: normal;|content={{anchors|first-line indent|first line indent|first line indentation|1st-line indent|1st-line indentation|1st line indent|1st line indentation|first-line|first line|1st-line|first line|firstline|firstline indent|firstline indentation}} For '''first-line indentation''' the first line of a paragraph is indented, {{unichar|2029|Paragraph Separator|html=}} }} {{defn|content= A first-line indentation of 2 em: <div style="background: #ECCFFF; width: 50%;"><div style="text-indent: 2em; border-left: thin solid #999999; border-right: thin solid #999999; padding-left: 1em; padding-right: 1em; margin-top: 0.5em; margin-bottom: 1em;">{{lorem ipsum}} </div></div> }} {{term|1=hanging indentation|style=font-weight: normal;|content={{anchor|hanging indent}} For '''hanging indentation''' all but the first line of a paragraph is indented. }} {{defn|content= A hanging indentation of 2 em: <div style="background: #FFFCFA; width: 50%;"><div style="padding-left: 3em; text-indent: -2em; border-left: thin solid #999999; border-right: thin solid #999999; padding-right:1em; margin-top: 0.5em; margin-bottom: 1em;">{{lorem ipsum}}</div></div> }} {{term|1=block indentation|style=font-weight: normal;|content={{anchor|block indent|block quote|block quotation|blockquote}} For '''block indentation''' the entire paragraph is indented relative to the preceding paragraph. }} {{defn|content= A block indentation of 2 em on the left: <div style="background: #FFFCFA; width: 50%;"><div style="padding-left: 3em; border-left: thin solid #999999; border-right: thin solid #999999; padding-right:1em; margin-top: 0.5em; margin-bottom: 1em;">{{lorem ipsum}}</div></div> }} {{defn|1=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 [[Typographic alignment|right-aligned]], the empty space on the right varies based on line length: <div style="background: #FFFCFA; width: 50%;"><div style="padding-left: 3em; padding-right:3em; border-left: thin solid #999999; border-right: thin solid #999999; margin-top: 0.5em; margin-bottom: 1em;">{{lorem ipsum}}</div></div> }} {{defn|1=Here's the same as the previous but justified (left and right aligned): <div style="background: #FFFCFA; width: 50%;"><div style="padding-left: 3em; padding-right:3em; text-align: justify; border-left: thin solid #999999; border-right: thin solid #999999; margin-top: 0.5em; margin-bottom: 1em;">{{lorem ipsum}}</div></div> }} {{glossary end}} == Indentation in programming == {{See also|Indentation style}} In [[computer programming]], indentation describes formatting [[source code]] with [[Whitespace (computers)|whitespace]] to the left of code text {{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 (computing)|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 [[neologism]]s '''outdent''', '''unindent''' and '''dedent''' describe the opposite of indentation {{endash}} 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 (punctuation)|space]] or [[tab character|tab]] characters. Although there are common practices, consensus is not universal. <ref>{{cite web|url=http://www.jwz.org/doc/tabs-vs-spaces.html |title=Tabs versus Spaces: An Eternal Holy War |website=Jwz.org |date=2007-01-05 |access-date=2014-01-18}}</ref> 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. {| class="wikitable" |- !Language !! Free-form? !! Note |- | [[Bash (Unix shell)|Bash]] || {{Yes}} || Fritz Mehner's style guide suggests 2, 4, or 8 spaces and uses 2 in all examples<ref>{{cite web|url=https://lug.fh-swf.de/vim/vim-bash/StyleGuideShell.en.pdf|title=Bash Style Guide and Coding Standard|website=Lug.fh-swf.de}}</ref> [[Google]] uses 2 spaces <ref>{{cite web |url=https://google-styleguide.googlecode.com/svn/trunk/shell.xml |title=Archived copy |access-date=2014-06-23 |url-status=dead |archive-url=https://web.archive.org/web/20140626134128/http://google-styleguide.googlecode.com/svn/trunk/shell.xml |archive-date=2014-06-26 }} </ref> |- | [[C (programming language)|C]] || {{Yes}} || The [[Linux kernel]] uses 1 tab<ref>{{cite web |url=https://www.kernel.org/doc/Documentation/CodingStyle |title=Archived copy |access-date=2015-02-15 |url-status=dead |archive-url=https://web.archive.org/web/20150214004842/https://www.kernel.org/doc/Documentation/CodingStyle |archive-date=2015-02-14 }} </ref><ref> {{cite web |url=https://www.kernel.org/doc/html/latest/process/coding-style.html |title=Linux kernel coding style |access-date=2022-07-21 |url-status=live |archive-url=https://web.archive.org/web/20220611181038/https://www.kernel.org/doc/html/latest/process/coding-style.html |archive-date=2022-06-11 }} </ref> [[NASA]] uses 4 spaces.<ref>{{cite web|url=https://ntrs.nasa.gov/citations/19950022400|title=C STYLE GUIDE|date=August 1994|website=NASA Technical Reports Server}}</ref> Clinton Staley advocates 3 spaces<ref>{{Cite web|last=Staley|first=Clinton|date=2006|title=C Program Style Rules|url=https://users.csc.calpoly.edu/~cstaley/General/CStyle.htm|website=Cal Poly Department of Computer Science & Software Engineering}}</ref> |- | [[C++]] || {{Yes}} || WebKit recommends 4 spaces<ref>{{Cite web|date=2015-11-07|title=Code Style Guidelines|url=https://webkit.org/code-style-guidelines/|access-date=2021-12-31|website=WebKit}}</ref> Google uses 2 spaces<ref>[http://google-styleguide.googlecode.com/svn/trunk/cppguide.html#Spaces_vs._Tabs] {{webarchive|url=https://web.archive.org/web/20141006093744/http://google-styleguide.googlecode.com/svn/trunk/cppguide.html|date=2014-10-06}}</ref> |- | [[C Sharp (programming language)|C#]] || {{Yes}} || [[Microsoft]] convention: 4 spaces<ref>{{cite web|url=http://msdn.microsoft.com/en-us/library/vstudio/ff926074.aspx|title=C# Coding Conventions (C# Programming Guide)|author=Bill Wagner|website=Msdn.microsoft.com|access-date=3 September 2017}}</ref> |- | [[CSS]] || {{Yes}} || [[Drupal]], [[GitHub]], and Google use 2 spaces<ref>{{cite web|url=https://drupal.org/node/1887862 |title=CSS formatting guidelines |website=Drupal.org |date=14 January 2013 |access-date=2014-01-18}}</ref><ref>{{cite web|url=https://github.com/styleguide/css |title=CSS Β· Styleguide Β· GitHub |website=Github.com |access-date=2014-01-18}}</ref><ref name="google">{{cite web |url=http://google-styleguide.googlecode.com/svn/trunk/htmlcssguide.xml#Indentation |title=Google HTML/CSS Style Guide |at=Indentation |quote=Indent by 2 spaces at a time. |work=Google GitHub |access-date=2016-03-13 |archive-url=https://web.archive.org/web/20160313125550/https://google-styleguide.googlecode.com/svn/trunk/htmlcssguide.xml#Indentation |archive-date=2016-03-13 |url-status=dead }} This is an HTML-rendered copy of the official version, which is maintained in XML format</ref><ref>{{cite web|url=https://github.com/google/styleguide|title=styleguide: Style guides for Google-originated open-source projects|date=3 September 2017|website=Github.com|access-date=3 September 2017}}</ref> [[WordPress]] uses tabs<ref>{{cite web|url=https://make.wordpress.org/core/handbook/best-practices/coding-standards/css/#structure |title=WordPress βΊ CSS Coding Standards Β« Make WordPress Core |website=Make.wordpress.org |date=17 July 2012 |access-date=2018-07-20}}</ref> |- | [[Dart (programming language)|Dart]] || {{Yes}} || <code>dart format</code> uses 2 spaces |- | [[Delphi (programming language)|Delphi]] || {{Yes}} || Delphi style guide: 2 spaces <ref>{{cite web|url=https://docwiki.embarcadero.com/RADStudio/Alexandria/en/White_Space_Usage#Indentation|title=Delphi's Object Pascal Style Guide - White Space Usage|access-date=13 December 2022 |language=en-us}}</ref> |- | [[F Sharp (programming language)|F#]] || {{Yes}} || F# style guide: 4 spaces<ref>{{cite web |title=F# code formatting guidelines |url=https://docs.microsoft.com/en-us/dotnet/fsharp/style-guide/formatting |website=docs.microsoft.com |access-date=14 October 2020 |language=en-us}}</ref> |- | [[Go (programming language)|Go]] || {{Yes}} || ''Effective Go'': 1 tab <ref>{{cite web|url=http://golang.org/doc/effective_go.html|title=Effective Go β The Go Programming Language|website=golang.org|access-date=3 September 2017}}</ref> |- | [[Haskell (programming language)|Haskell]] || {{No}} || Google uses 2 spaces<ref>{{cite web|url=https://code.google.com/p/ganeti/wiki/HaskellStyleGuide#Indentation |title=HaskellStyleGuide β ganeti β Style Guide for the Haskell code β Cluster-based virtualization management software β Google Project Hosting |website=Code.google.com |date=2014-01-08 |access-date=2014-01-18 |url-status=dead |archive-url=https://web.archive.org/web/20130627194135/http://code.google.com/p/ganeti/wiki/HaskellStyleGuide |archive-date=June 27, 2013 }}</ref> |- | [[HTML]] || {{Yes}} || Google uses 2 spaces<ref name="google" /> [[HTML Tidy]] defaults to 2 spaces<ref>{{cite web|url=http://tidy.sourceforge.net/docs/quickref.html#indent-spaces |title=HTML Tidy Configuration Options Quick Reference |website=Tidy.sourceforge.net |date=2008-06-18 |access-date=2014-01-18}}</ref> |- | [[Java (programming language)|Java]] || {{Yes}} || [[Oracle Corporation|Oracle]] uses 4 spaces<ref>{{cite web|url=http://www.oracle.com/technetwork/java/javase/documentation/codeconventions-136091.html#262 |title=Code Conventions for the Java Programming Language: 4. Indentation |website=Oracle.com |access-date=2014-01-18}}</ref> [[Android (operating system)|Android]] uses 4 spaces<ref>{{cite web|url=http://source.android.com/source/code-style.html#use-spaces-for-indentation |title=Code Style Guidelines for Contributors | Android Developers |website=Source.android.com |access-date=2014-01-18}}</ref> Most [[Eclipse (software)|Eclipse IDE]] components use tabs |- | [[JavaScript]] || {{Yes}} || [[Douglas Crockford]] advocates 4 spaces<ref>{{cite web|url=http://javascript.crockford.com/code.html |title=Code Conventions for the JavaScript Programming Language |website=Javascript.crockford.com |date=2006-11-13 |access-date=2014-01-18}}</ref> GitHub and Google use 2 spaces<ref>{{cite web |url=https://github.com/styleguide/javascript |title=JavaScript θ·― Styleguide |website=Github.com |access-date=2014-01-18 |url-status=dead |archive-url=https://web.archive.org/web/20130815075924/https://github.com/styleguide/javascript |archive-date=2013-08-15 }}</ref><ref>{{cite web |url=http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml#Code_formatting |title=JaveScript Style Rules |website=Google-styleguide.googlecode.com |access-date=2014-02-18 |archive-url=https://web.archive.org/web/20140216111413/http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml#Code_formatting |archive-date=2014-02-16 |url-status=dead }}</ref> [[jQuery]] uses tabs<ref>{{cite web|author=jQuery Foundation - jquery.org |url=http://contribute.jquery.org/style-guide/js/ |title=JavaScript Style Guide | Contribute to jQuery |website=Contribute.jquery.org |access-date=2014-01-18}}</ref> [[Firefox]]'s built-in jsbeautifier defaults to 2 spaces [[prettyprint]]er in [[Google Chrome]] and [[Internet Explorer]] use 4 spaces |- | [[Julia (programming language)|Julia]] | {{Yes}} | Julia style guide: 4 spaces<ref>{{cite web |title=Style Guide Β· The Julia Language |url=https://docs.julialang.org/en/v1.6/manual/style-guide/#Indentation |website=docs.julialang.org}}</ref> |- | [[Kotlin (programming language)|Kotlin]] | {{Yes}} | Kotlin style guide: 4 spaces<ref>{{cite web |title=Coding Conventions β Kotlin Programming Language |url=https://kotlinlang.org/docs/reference/coding-conventions.html |website=Kotlin}}</ref> |- | [[Lua (programming language)|Lua]] || {{Yes}} || Lua style guide: 2 spaces<ref>{{cite web|url=http://lua-users.org/wiki/LuaStyleGuide|title=lua-users wiki: Lua Style Guide|website=lua-users.org|access-date=3 September 2017}}</ref> |- | [[Perl]] || {{Yes}} || [[Larry Wall]] prefers 4 spaces<ref>{{cite web |url= http://perldoc.perl.org/perlstyle.html |title=perlstyle: Perl style guide |work=Perl 5 Version 32.1 Documentation |editor-first=Jon (JJ) |editor-last=Allen |publisher=Perl Foundation |access-date=2021-04-19}}</ref> |- | [[PHP]] || {{Yes}} || [[Drupal]] use 2 spaces<ref>{{cite web|url=https://drupal.org/coding-standards#indenting |title=Coding standards |website=Drupal.org |access-date=2014-01-18}}</ref> PEAR and Zend use 4 spaces<ref>{{cite web|url=http://pear.php.net/manual/en/standards.indenting.php |title=Manual :: Indenting and Line Length |website=Pear.php.net |access-date=2014-01-18}}</ref><ref>{{cite web |url=http://framework.zend.com/wiki/display/ZFDEV/PHP+Coding+Standard+%28draft%29 |title=PHP Coding Standard (draft) β Contributors β Zend Framework Wiki |website=Framework.zend.com |access-date=2014-01-18 |archive-url=https://web.archive.org/web/20080103203245/http://framework.zend.com/wiki/display/ZFDEV/PHP+Coding+Standard+(draft) |archive-date=2008-01-03 |url-status=dead }}</ref> CodeIgniter and WordPress use tabs<ref>{{cite web |url=http://ellislab.com/codeigniter/user-guide/general/styleguide.html#code_indenting |title=Style Guide : CodeIgniter User Guide |website=Ellislab.com |access-date=2014-01-18 |archive-date=1 June 2013 |archive-url=https://web.archive.org/web/20130601111626/http://ellislab.com/codeigniter/user-guide/general/styleguide.html#code_indenting |url-status=dead }}</ref><ref>{{cite web|url=http://make.wordpress.org/core/handbook/coding-standards/php/#indentation |title=WordPress βΊ PHP Coding Standards Β« Make WordPress Core |website=Make.wordpress.org |date=23 July 2012 |access-date=2014-01-18}}</ref> PSR-2 specifies 4 spaces<ref>{{cite web |url=http://www.php-fig.org/psr/2/ |website=Php-fig.org |access-date=2014-02-18 |title=PHP : Coding Style Guide |url-status=dead |archive-url=https://web.archive.org/web/20140315044508/http://www.php-fig.org/psr/2/ |archive-date=2014-03-15 }}</ref> |- | [[PowerShell]] || {{Yes}} || Unofficial PowerShell Best Practices and Style Guide: 4 spaces<ref>{{cite web |title=Code Layout and Formatting β PowerShell Practice and Style |url=https://poshcode.gitbook.io/powershell-practice-and-style/style-guide/code-layout-and-formatting |website=PowerShell Practice and Style |access-date=17 October 2021}}</ref> |- | [[Python (programming language)|Python]] || {{No}} || PEP 8: 4 spaces<ref>{{cite web|url=https://www.python.org/dev/peps/pep-0008/#indentation|title=PEP 8 β Style Guide for Python Code|website=Python.org|access-date=3 September 2017}}</ref> |- | [[Ruby (programming language)|Ruby]] || {{Yes}} || Ruby style guide: 2 spaces <ref>{{cite web|url=https://github.com/bbatsov/ruby-style-guide|title=ruby-style-guide: A community-driven Ruby coding style guide|first=Bozhidar|last=Batsov|date=3 September 2017|access-date=3 September 2017|website=Github.com}}</ref> |- | [[Rust (programming language)|Rust]] || {{Yes}} || Rust style guide: 4 spaces <ref>{{cite web|url=https://github.com/rust-lang/rust|title=rust: A safe, concurrent, practical language|date=3 September 2017|website=Github.com|access-date=3 September 2017}}</ref> |- | [[Scala (programming language)|Scala]] || {{Yes}} || Scala style guide: 2 spaces <ref>{{cite web|url=http://docs.scala-lang.org/style/indentation.html|title=Indentation β Scala Documentation|website=docs.scala-lang.org|access-date=3 September 2017}}</ref> |- | [[Swift (programming language)|Swift]] || {{Yes}} || Google uses 2 spaces<ref>{{cite web |title=Swift Style Guide |url=https://google.github.io/swift/ |website=google.github.io |access-date=17 October 2021}}</ref> |- | [[Tcl]] || {{Yes}} || Tcl style guide: 4 spaces <ref>{{cite web|url=http://www.tcl.tk/doc/styleGuide.pdf|title=Tcl Style Guide|author=Ray Johnson|website=Tcl.tk|access-date=3 September 2017}}</ref> |- | [[Visual Basic .NET|Visual Basic]] || {{Yes}} || Microsoft convention: 4 spaces <ref>{{cite web|url=http://msdn.microsoft.com/en-us/library/aa733583(v=vs.60).aspx|title=Structured Coding Conventions|website=msdn.microsoft.com|date=4 January 2007 |access-date=3 September 2017}}</ref> |- | [[XML]] || {{Yes}} || Google uses 2 spaces<ref>{{cite web |title=Google XML Document Format Style Guide |url=https://google.github.io/styleguide/xmlstyle.html |website=google.github.io |publisher=Google |access-date=17 October 2021}}</ref> |} === Elastic tabstops === In 2006, a new method of indentation was proposed, called [[elastic tabstops]].{{cn|date=March 2024}} ==References== {{Reflist}} {{Commons cat|Indentation (typesetting)}} [[Category:Typography]] [[Category:Source code]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:Cite web
(
edit
)
Template:Cn
(
edit
)
Template:Commons cat
(
edit
)
Template:Defn
(
edit
)
Template:Endash
(
edit
)
Template:Glossary begin
(
edit
)
Template:Glossary end
(
edit
)
Template:No
(
edit
)
Template:Redirect
(
edit
)
Template:Reflist
(
edit
)
Template:See also
(
edit
)
Template:Short description
(
edit
)
Template:Term
(
edit
)
Template:Use dmy dates
(
edit
)
Template:Webarchive
(
edit
)
Template:Wiktionary
(
edit
)
Template:Yes
(
edit
)