__FORCETOC__
In the written form of many
language
Language is a structured system of communication that consists of grammar and vocabulary. It is the primary means by which humans convey meaning, both in spoken and signed language, signed forms, and may also be conveyed through writing syste ...
s, 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
A paragraph () is a self-contained unit of discourse in writing dealing with a particular point or idea. Though not required by the orthographic conventions of any language with a writing system, paragraphs are a conventional means of organizing ...
*
Hierarchy
A hierarchy (from Ancient Greek, Greek: , from , 'president of sacred rites') is an arrangement of items (objects, names, values, categories, etc.) that are represented as being "above", "below", or "at the same level as" one another. Hierarchy ...
subordinate concept
*
Quotation
A quotation or quote is the repetition of a sentence, phrase, or passage from speech or text that someone has said or written. In oral speech, it is the representation of an utterance (i.e. of something that a speaker actually said) that is intro ...
Many
computer languages use ''block indentation'' to demarcate
blocks of
source code
In computing, source code, or simply code or source, is a plain text computer program written in a programming language. A programmer writes the human readable source code to control the behavior of a computer.
Since a computer, at base, only ...
.
Indentation is essentially the same regardless of whether the
writing system
A writing system comprises a set of symbols, called a ''script'', as well as the rules by which the script represents a particular language. The earliest writing appeared during the late 4th millennium BC. Throughout history, each independen ...
is left-to-right (e.g.
Latin
Latin ( or ) is a classical language belonging to the Italic languages, Italic branch of the Indo-European languages. Latin was originally spoken by the Latins (Italic tribe), Latins in Latium (now known as Lazio), the lower Tiber area aroun ...
and
Cyrillic
The Cyrillic script ( ) is a writing system used for various languages across Eurasia. It is the designated national script in various Slavic, Turkic, Mongolic, Uralic, Caucasian and Iranic-speaking countries in Southeastern Europe, Ea ...
) or right-to-left (e.g.
Hebrew
Hebrew (; ''ʿÎbrit'') is a Northwest Semitic languages, Northwest Semitic language within the Afroasiatic languages, Afroasiatic language family. A regional dialect of the Canaanite languages, it was natively spoken by the Israelites and ...
and
Arabic
Arabic (, , or , ) is a Central Semitic languages, Central Semitic language of the Afroasiatic languages, Afroasiatic language family spoken primarily in the Arab world. The International Organization for Standardization (ISO) assigns lang ...
) 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
''Lorem ipsum'' ( ) is a dummy or placeholder text commonly used in graphic design, publishing, and web development. Its purpose is to permit a page layout to be designed, independently of the copy (publishing), copy that will subsequently pop ...
content. The width of indentation here is in units of
em spaces.
Indentation in programming
In
computer programming
Computer programming or coding is the composition of sequences of instructions, called computer program, programs, that computers can follow to perform tasks. It involves designing and implementing algorithms, step-by-step specifications of proc ...
, indentation describes formatting
source code
In computing, source code, or simply code or source, is a plain text computer program written in a programming language. A programmer writes the human readable source code to control the behavior of a computer.
Since a computer, at base, only ...
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
A hierarchy (from Greek: , from , 'president of sacred rites') is an arrangement of items (objects, names, values, categories, etc.) that are represented as being "above", "below", or "at the same level as" one another. Hierarchy is an importan ...
structure
A structure is an arrangement and organization of interrelated elements in a material object or system, or the object or system so organized. Material structures include man-made objects such as buildings and machines and natural objects such as ...
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
A whitespace character is a character (computing), character data element that represents White space (visual arts), white space when text string, text is
Rendering (computer graphics), rendered for display by a computer.
For example, a ''Space ...
.
For a
free-form language, indentation is exclusively for the
programmer
A programmer, computer programmer or coder is an author of computer source code someone with skill in computer programming.
The professional titles Software development, ''software developer'' and Software engineering, ''software engineer' ...
since a code processor (i.e.
compiler
In computing, a compiler is a computer program that Translator (computing), translates computer code written in one programming language (the ''source'' language) into another language (the ''target'' language). The name "compiler" is primaril ...
,
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
The off-side rule describes syntax of a computer programming language that defines the bounds of a code block via indentation.
The term was coined by Peter Landin, possibly as a pun on the offside law in association football.
An off-side ...
. Due to this
syntax
In linguistics, syntax ( ) is the study of how words and morphemes combine to form larger units such as phrases and sentences. Central concerns of syntax include word order, grammatical relations, hierarchical sentence structure (constituenc ...
requirement, the code must have a level of consistency that is not required in free-form language code.
The
neologism
In linguistics, a neologism (; also known as a coinage) is any newly formed word, term, or phrase that has achieved popular or institutional recognition and is becoming accepted into mainstream language. Most definitively, a word can be considered ...
s 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
A whitespace character is a character (computing), character data element that represents White space (visual arts), white space when text string, text is
Rendering (computer graphics), rendered for display by a computer.
For example, a ''Space ...
as
space
Space is a three-dimensional continuum containing positions and directions. In classical physics, physical space is often conceived in three linear dimensions. Modern physicists usually consider it, with time, to be part of a boundless ...
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
An organization or organisation (English in the Commonwealth of Nations, Commonwealth English; American and British English spelling differences#-ise, -ize (-isation, -ization), see spelling differences) is an legal entity, entity—such as ...
mandate and personal preference.
Common practices
The following table identifies notable practices with respect to code indentation.
Elastic tabstops
In 2006, a new method of indentation was proposed, called
elastic tabstops.
References
{{Commons cat, Indentation (typesetting)
Typography
Source code