reStructuredText Markup Specification
- Contact:
- docutils-develop@lists.sourceforge.net
- Revision:
- 10399
- Date:
- 2026-09-05
- Copyright:
- This document has been placed in the public domain.
reStructuredText is plaintext that uses simple and intuitive constructs to indicate the structure of a document. These constructs are equally easy to read in raw and processed forms. This document is itself an example of reStructuredText (raw, if you are reading the text file, or processed, if you are reading an HTML document, for example). The reStructuredText parser is a component of Docutils.
Simple, implicit markup is used to indicate special constructs, such as section headings, bullet lists, and emphasis. The markup used is as minimal and unobtrusive as possible. Less often-used constructs and extensions to the basic reStructuredText syntax may have more elaborate or explicit markup.
reStructuredText is applicable to documents of any length, from the very small (such as inline program documentation fragments, e.g. Python docstrings) to the quite large (this document).
The first section gives a quick overview of the syntax of the reStructuredText markup by example. A complete specification is given in the Syntax Details section.
Literal blocks (in which no markup processing is done) are used for examples throughout this document, to illustrate the plaintext markup.
Quick Syntax Overview
A reStructuredText document is made up of body or block-level elements, and may be structured into sections. Sections are indicated through title style (underlines & optional overlines). Sections contain body elements and/or subsections. Some body elements contain further elements, such as lists containing list items, which in turn may contain paragraphs and other body elements. Others, such as paragraphs, contain text and inline markup elements.
Here are examples of body elements:
Paragraphs (and inline markup):
Paragraphs contain text and may contain inline markup: *emphasis*, **strong emphasis**, `interpreted text`, ``inline literals``, standalone hyperlinks (https://www.python.org), external hyperlinks (Python_), internal cross-references (example_), footnote references ([1]_), citation references ([CIT2002]_), substitution references (|example|), and _`inline internal targets`. Paragraphs are separated by blank lines and are left-aligned.
Five types of lists:
-
- This is a bullet list. - Bullets can be ``*``, ``+``, or ``-``.
-
1. This is an enumerated list. 2. Enumerators may be arabic numerals, letters, or roman numerals.
-
what Definition lists associate a term with a definition. how The term is a one-line phrase, and the definition is one or more paragraphs or body elements, indented relative to the term. -
:what: Field lists map field names to field bodies, like database records. They are often part of an extension syntax. :how: The field marker is a colon, the field name, and a colon. The field body may contain one or more body elements, indented relative to the field marker. Option lists, for listing command-line options:
-a command-line option "a" -b file options can have arguments and long descriptions --long options can be long also --input=file long options can also have arguments /V DOS/VMS-style options tooThere must be at least two spaces between the option and the description.
-
-
Literal blocks are either indented or line-prefix-quoted blocks, and indicated with a double-colon (``::``) at the end of the preceding paragraph (right here -->):: if literal_block: text = 'is left as-is' spaces_and_linebreaks = 'are preserved' markup_processing = None -
Block quotes consist of indented body elements: This theory, that is mine, is mine. -- Anne Elk (Miss) -
>>> print 'Python-specific usage examples; begun with ">>> "' Python-specific usage examples; begun with ">>> " >>> print '(cut and pasted from interactive Python sessions)' (cut and pasted from interactive Python sessions)
Two syntaxes for tables:
Grid tables; complete, but complex and verbose:
+------------------------+------------+----------+ | Header row, column 1 | Header 2 | Header 3 | +========================+============+==========+ | body row 1, column 1 | column 2 | column 3 | +------------------------+------------+----------+ | body row 2 | Cells may span | +------------------------+-----------------------+
Simple tables; easy and compact, but limited:
==================== ========== ========== Header row, column 1 Header 2 Header 3 ==================== ========== ========== body row 1, column 1 column 2 column 3 body row 2 Cells may span columns ==================== ======================
Explicit markup blocks all begin with an explicit block marker, two periods and a space:
-
.. [1] A footnote contains body elements, consistently indented by at least 1 space. The least indented line sets the reference indentation, so this is a nested block quote. -
.. [CIT2002] Just like a footnote, except the label is textual.
-
.. _Python: https://www.python.org .. _example: The "_example" target above points to this paragraph.
-
.. image:: mylogo.png
-
.. |symbol here| image:: symbol.png
-
.. Comments begin with two dots and whitespace. Anything may follow, except for the syntax of footnotes/citations, hyperlink targets, directives, or substitution definitions.
-
Syntax Details
Descriptions below list "doctree elements" (document tree element names; XML DTD generic identifiers) corresponding to syntax constructs. For details on the hierarchy of elements, please see The Docutils Document Tree and the Docutils Generic DTD XML document type definition.
Whitespace
- Config setting:
Spaces are recommended for indentation, but tabs may also be used. Tabs will be converted to spaces. Tab stops are at every 8th column (processing systems may make this value configurable, Docutils uses the tab_width configuration setting).
Other whitespace characters (form feeds [chr(12)] and vertical tabs [chr(11)]) are converted to single spaces before processing.
Blank Lines
Blank lines are used to separate paragraphs and other elements. Multiple successive blank lines are equivalent to a single blank line, except within literal blocks (where all whitespace is preserved). Blank lines may be omitted when the markup makes element separation unambiguous, in conjunction with indentation. The first line of a document is treated as if it is preceded by a blank line, and the last line of a document is treated as if it is followed by a blank line.
Indentation
When a paragraph or other construct consists of more than one line of text, the lines must be left-aligned:
This is a paragraph. The lines of
this paragraph are aligned at the left.
This paragraph has problems. The
lines are not left-aligned. In addition
to potential misinterpretation, warning
and/or error messages will be generated
by the parser.
Indentation is used to indicate -- and is only significant in indicating -- block quotes, definitions (in definition lists), and local nested content:
list item content (multi-line contents of list items, and multiple body elements within a list item, including nested lists),
the content of literal blocks, and
the content of explicit markup blocks (directives, footnotes, ...).
Any text whose indentation is less than that of the current level (i.e., unindented text or "dedents") ends the current level of indentation.
Since all indentation is significant, the level of indentation must be consistent. For example, indentation is the sole markup indicator for block quotes:
This is a top-level paragraph.
This paragraph belongs to a first-level block quote.
Paragraph 2 of the first-level block quote.
Multiple levels of indentation within a block will result in more complex structures. The least indented line of a block sets the reference indentation:
This is a top-level paragraph.
This paragraph belongs to a first-level block quote.
This paragraph belongs to a second-level block quote.
Another top-level paragraph.
This paragraph belongs to a second-level block quote.
This paragraph belongs to a first-level block quote.
The second-level block quote above is inside this
first-level block quote.
Every block has its own reference indentation::
This paragraph belongs to a first-level block quote
because there is no less indented line in the block.
Several constructs begin with a marker, and the body of the construct must be indented relative to the marker. For constructs using simple markers (bullet lists, enumerated lists), the level of indentation of the body is determined by the position of the first line of text. For example:
- This is the first line of a bullet list
item's paragraph. All lines must align
relative to the first line.
This indented paragraph is interpreted
as a block quote.
Another paragraph belonging to the first list item.
Because it is not sufficiently indented,
this paragraph does not belong to the list
item (it's a block quote following the list).
The first line of text may start below the marker:
1. This is the first line of an enumeration item's paragraph. This indented paragraph is interpreted as a block quote. This paragraph still belongs to the list item This paragraph ends the list.
The body of explicit markup blocks, field lists, and option lists ends above the first line with the same or less indentation than the marker. For example, field lists may have very long markers (containing the field names):
:Hello: This field has a short field name, so aligning
the field body with the first line is feasible.
:Long field name: It would be inconvenient to align the
field body with the left edge of the first line.
:Number of African swallows required to carry a coconut:
Sometimes, it is preferable to begin the body
on the next line.
Escaping Mechanism
The character set universally available to plaintext documents, 7-bit ASCII, is limited. No matter what characters are used for markup, they will already have multiple meanings in written text. Therefore markup characters will sometimes appear in text without being intended as markup. Any serious markup system requires an escaping mechanism to override the default meaning of the characters used for the markup. In reStructuredText we use the backslash, commonly used as an escaping character in other domains.
A backslash (\) escapes the following character.
"Escaping" backslash characters are represented by NULL characters in the Document Tree and removed from the output document by the Docutils writers.
Escaped non-white characters are prevented from playing a role in any markup interpretation. The escaped character represents the character itself. (A literal backslash can be specified by two backslashes in a row -- the first backslash escapes the second. [1])
Escaped whitespace characters are removed from the output document together with the escaping backslash. This allows for character-level inline markup.
In URI context [2], backslash-escaped whitespace represents a single space.
Backslashes have no special meaning in literal context [3]. Here, a single backslash represents a literal backslash, without having to double up. [1]
Reference Names
Reference names identify elements for cross-referencing.
Note
References to a target position in external, generated documents must use the auto-generated identifier key which may differ from the reference name due to restrictions on identifiers/labels in the output format.
Simple reference names are single words consisting of alphanumerics plus isolated (no two adjacent) internal hyphens, underscores, periods, colons and plus signs; no whitespace or other characters are allowed. Footnote labels (Footnotes & Footnote References), citation labels (Citations & Citation References), interpreted text roles, and some hyperlink references use the simple reference name syntax.
Reference names using punctuation or whose names are phrases (two or more space-separated words) are called phrase references. Phrase-references are expressed by enclosing the phrase in backquotes and treating the backquoted text as a reference name:
Want to learn about `my favorite programming language`_? .. _my favorite programming language: https://www.python.org
Simple reference names may also optionally use backquotes.
Reference names are whitespace-neutral and case-insensitive [4]: When resolving reference names internally,
whitespace is normalized (one or more spaces, horizontal or vertical tabs, newlines, carriage returns, or form feeds, are interpreted as a single space), and
case is normalized (all alphabetic characters are converted to lowercase). [4]
For example, the following hyperlink references are equivalent:
- `A HYPERLINK`_ - `a hyperlink`_ - `A Hyperlink`_
Hyperlinks, footnotes, and citations all share the same namespace for reference names. [4] This means that a footnote defined as ".. [#note]" can be referred to by the footnote reference [#note]_ as well as a plain hyperlink reference note_. Of course, each type of reference (hyperlink, footnote, citation) may be processed and rendered differently. Some care should be taken to avoid reference name conflicts. [5]
Substitution references and substitution definitions use a different namespace. Matching is case-sensitive but forgiving.
Docutils' rules for handling duplicate reference names are described in section Implicit Hyperlink Targets.
Document Structure
Document
- Doctree element:
The top-level element of a parsed reStructuredText document is the "document" element. After initial parsing, the document element is a simple container for a document fragment, consisting of body elements, transitions, and sections, but lacking a document title or other bibliographic elements. The code that calls the parser may choose to run one or more optional post-parse transforms, rearranging the document fragment into a complete document with a title and possibly other metadata elements (author, date, etc.; see Bibliographic Fields).
Document Title
Specifically, there is no special syntax to indicate a document title and subtitle in reStructuredText. [6] Instead, a uniquely-adorned top-level section title can be treated as the document title. Similarly, a uniquely-adorned second-level section title immediately after the document title can become the document subtitle. The rest of the sections are then lifted up a level or two. See A ReStructuredText Primer for examples and the DocTitle transform for details.
The "title" directive sets the document's metadata title that does not become part of the document body.
Sections
Sections are identified through their titles, which are marked up with adornment: "underlines" below the title text, or underlines and matching "overlines" above the title. An underline/overline is a single repeated punctuation character that begins in column 1 and forms a line extending at least as far as the right edge of the title text. [7] Specifically, an underline/overline character may be any non-alphanumeric printable 7-bit ASCII character [8]. When an overline is used, the length and character used must match the underline. Underline-only adornment styles are distinct from overline-and-underline styles that use the same character. There may be any number of levels of section titles, although some output formats may have limits (HTML has 6 levels).
The key is the visual length of the title in a mono-spaced font. The adornment may need more or less characters than title, if the title contains wide or combining characters.
The following are all valid section title adornment characters:
! " # $ % & ' ( ) * + , - . / : ; < = > ? @ [ \ ] ^ _ ` { | } ~
Some characters are more suitable than others. The following are recommended:
= - ` : . ' " ~ ^ _ * + #
Rather than imposing a fixed number and order of section title adornment styles, the order enforced will be the order as encountered. The first style encountered will be an outermost title (like HTML <H1>), the second style will be a subtitle, the third will be a subsubtitle, and so on.
Below are examples of section title styles:
=============== Section Title =============== --------------- Section Title --------------- Section Title ============= Section Title ------------- Section Title ````````````` Section Title ''''''''''''' Section Title ............. Section Title ~~~~~~~~~~~~~ Section Title ************* Section Title +++++++++++++ Section Title ^^^^^^^^^^^^^
When a title has both an underline and an overline, the title text may be inset, as in the first two examples above. This is merely aesthetic and not significant. Underline-only title text may not be inset.
A blank line after a title is optional. All text blocks up to the next title of the same or higher level are included in a section (or subsection, etc.).
All section title styles need not be used, nor need any specific section title style be used. However, a document must be consistent in its use of section titles: once a hierarchy of title styles is established, sections must use that hierarchy. [9]
Each section title automatically generates a hyperlink target pointing to the section. The text of the hyperlink target (the reference name) is the same as that of the section title. See Implicit Hyperlink Targets for a complete description.
Sections may contain body elements, transitions, and nested sections.
Directives may establish a separate hierarchy of title styles for their content. This is handy for directives that include content from separate sources, e.g., the directives provided by the "autodoc" Sphinx extension.
Transitions
- Doctree element:
-
Instead of subheads, extra space or a type ornament between paragraphs may be used to mark text divisions or to signal changes in subject or emphasis.
(The Chicago Manual of Style, 14th edition, section 1.80)
Transitions are commonly seen in novels and short fiction, as a gap spanning one or more lines, with or without a type ornament such as a row of asterisks. Transitions separate other body elements. A transition should not begin or end a section or document, nor should two transitions be immediately adjacent.
The syntax for a transition marker is a horizontal line of 4 or more repeated punctuation characters. The syntax is the same as section title underlines without title text. Transition markers require blank lines before and after:
Para. ---------- Para.
Unlike section title underlines, no hierarchy of transition markers is enforced, nor do differences in transition markers accomplish anything. It is recommended that a single consistent style be used.
The processing system is free to render transitions in output in any way it likes. For example, horizontal rules (<hr>) in HTML output would be an obvious choice.
Body Elements
Paragraphs
- Doctree element:
Paragraphs consist of blocks of left-aligned text with no markup indicating any other body element. Blank lines separate paragraphs from each other and from other body elements. Paragraphs may contain inline markup.
Syntax diagram:
+------------------------------+ | paragraph | | | +------------------------------+ +------------------------------+ | paragraph | | | +------------------------------+
Bullet Lists
- Doctree elements:
A text block which begins with a *, +, -, •, ‣, or ⁃, followed by whitespace, is a bullet list item (a.k.a. "unordered" list item). List item bodies must be left-aligned and indented relative to the bullet; the text immediately after the bullet determines the indentation. For example:
- This is the first bullet list item. The blank line above the
first list item is required; blank lines between list items
(such as below this paragraph) are optional.
- This is the first paragraph in the second item in the list.
This is the second paragraph in the second item in the list.
The blank line above this paragraph is required. The left edge
of this paragraph lines up with the paragraph above, both
indented relative to the bullet.
- This is a sublist. The bullet lines up with the left edge of
the text blocks above. A sublist is a new list so requires a
blank line above and below.
- This is the third item of the main list.
This paragraph is not part of the list.
Here are examples of incorrectly formatted bullet lists:
- This first line is fine.
A blank line is required between list items and paragraphs.
(Warning)
- The following line appears to be a new sublist, but it is not:
- This is a paragraph continuation, not a sublist (since there's
no blank line). This line is also incorrectly indented.
- Warnings may be issued by the implementation.
Syntax diagram:
+------+-----------------------+
| "- " | list item |
+------| (body elements)+ |
+-----------------------+
Enumerated Lists
- Doctree elements:
Enumerated lists (a.k.a. "ordered" lists) are similar to bullet lists, but use enumerators instead of bullets. An enumerator consists of an enumeration sequence member and formatting, followed by whitespace. The following enumeration sequences are recognized:
arabic numerals: 1, 2, 3, ... (no upper limit).
uppercase alphabet characters: A, B, C, ..., Z.
lower-case alphabet characters: a, b, c, ..., z.
uppercase Roman numerals: I, II, III, IV, ..., MMMMCMXCIX (4999).
lowercase Roman numerals: i, ii, iii, iv, ..., mmmmcmxcix (4999).
In addition, the auto-enumerator, #, may be used to automatically enumerate a list. Auto-enumerated lists may begin with explicit enumeration, which sets the sequence and start value. Fully auto-enumerated lists use arabic numerals and begin with 1.
The following formatting types are recognized:
suffixed with a period: 1., A., a., I., i..
surrounded by parentheses: (1), (A), (a), (I), (i).
suffixed with a right-parenthesis: 1), A), a), I), i).
While parsing an enumerated list, a new list will be started whenever:
An enumerator is encountered which does not have the same format and sequence type as the current list (e.g. 1., (a) produces two separate lists).
The enumerators are not in sequence (e.g., 1., 3. produces two separate lists).
It is recommended that the enumerator of the first list item be ordinal-1 (1, A, a, I, or i). Although other start-values will be recognized, they may not be supported by the output format. A level-1 [info] system message will be generated for any list beginning with a non-ordinal-1 enumerator.
Lists using Roman numerals must begin with I/i or a multi-character value, such as II or XV. Any other single-character Roman numeral (V, X, L, C, D, M) will be interpreted as a letter of the alphabet, not as a Roman numeral. Likewise, lists using letters of the alphabet may not begin with I/i, since these are recognized as Roman numeral 1.
The second line of each enumerated list item is checked for validity. This is to prevent ordinary paragraphs from being mistakenly interpreted as list items, when they happen to begin with text identical to enumerators. For example, this text is parsed as an ordinary paragraph:
A. Einstein was a really smart dude.
However, ambiguity cannot be avoided if the paragraph consists of only one line. This text is parsed as an enumerated list item:
A. Einstein was a really smart dude.
Caution!
If a single-line paragraph begins with text identical to an enumerator (A., 1., (b), I), etc.), the first character will have to be escaped in order to have the line parsed as an ordinary paragraph:
\A. Einstein was a really smart dude.
Alternatively, you can escape the delimiter
A\. Einstein was a really smart dude.
or use a literal NO-BREAK SPACE after the initial.
Examples of nested enumerated lists:
1. Item 1 initial text. a) Item 1a. b) Item 1b. 2. a) Item 2a. b) Item 2b.
Example syntax diagram:
+-------+----------------------+
| "1. " | list item |
+-------| (body elements)+ |
+----------------------+
Definition Lists
- Doctree elements:
<definition_list>, <definition_list_item>, <term>, <classifier>, <definition>
Each definition list item contains a term, optional classifiers, and a definition.
A term is a simple one-line word or phrase. Escape a leading hyphen to prevent recognition as an option list item.
Optional classifiers may follow the term on the same line, each after an inline : (space, colon, space). Inline markup is parsed in the term line before the classifier delimiters are recognized. A delimiter will only be recognized if it appears outside of any inline markup.
A definition is a block indented relative to the term, and may contain multiple paragraphs and other body elements. There may be no blank line between a term line and a definition block (this distinguishes definition lists from block quotes). Blank lines are required before the first and after the last definition list item, but are optional in-between.
Example:
term 1
Definition 1.
term 2
Definition 2, paragraph 1.
Definition 2, paragraph 2.
term 3 : classifier
Definition 3.
term 4 : classifier one : classifier two
Definition 4.
\-term 5
Without escaping, this would be an option list item.
A definition list may be used in various ways, including:
As a dictionary or glossary. The term is the word itself, a classifier may be used to indicate the usage of the term (noun, verb, etc.), and the definition follows.
To describe program variables. The term is the variable name, a classifier may be used to indicate the type of the variable (string, integer, etc.), and the definition describes the variable's use in the program. This usage of definition lists supports the classifier syntax of Grouch, a system for describing and enforcing a Python object schema.
Syntax diagram:
+----------------------------+ | term [ " : " classifier ]* | +--+-------------------------+--+ | definition | | (body elements)+ | +----------------------------+
Field Lists
- Doctree elements:
Field lists are used as part of an extension syntax, such as options for directives, or database-like records meant for further processing. They may also be used for two-column table-like structures resembling database records (label & data pairs). Applications of reStructuredText may recognize field names and transform fields or field bodies in certain contexts. For examples, see Bibliographic Fields or directive options below or the "meta" directive.
Field lists are mappings from field names to field bodies, modeled on RFC822 headers. A field name may consist of any characters, but colons (:) inside of field names must be backslash-escaped when followed by whitespace.[10] Inline markup is parsed in field names, but care must be taken when using interpreted text with explicit roles in field names: the role must be a suffix to the interpreted text. Field names are case-insensitive when further processed or transformed. The field name, along with a single colon prefix and suffix, together form the field marker. The field marker is followed by whitespace and the field body. The field body may contain multiple body elements, indented relative to the field marker. The first line after the field name marker determines the indentation of the field body. For example:
:Date: 2001-08-16
:Version: 1
:Authors: - Me
- Myself
- I
:Indentation: Since the field marker may be quite long, the second
and subsequent lines of the field body do not have to line up
with the first line, but they must be indented relative to the
field name marker, and they must line up with each other.
:Parameter i: integer
The interpretation of individual words in a multi-word field name is up to the application. The application may specify a syntax for the field name. For example, second and subsequent words may be treated as "arguments", quoted phrases may be treated as a single argument, and direct support for the "name=value" syntax may be added.
Standard RFC822 headers cannot be used for this construct because they are ambiguous. A word followed by a colon at the beginning of a line is common in written text. However, in well-defined contexts such as when a field list invariably occurs at the beginning of a document (PEPs and email messages), standard RFC822 headers could be used.
Syntax diagram (simplified):
+--------------------+----------------------+
| ":" field name ":" | field body |
+-------+------------+ |
| (body elements)+ |
+-----------------------------------+
Up to Docutils 0.14, field markers were not recognized when containing a colon.
Bibliographic Fields
- Doctree elements:
<docinfo>, <address>, <author>, <authors>, <contact>, <copyright>, <date>, <organization>, <revision>, <status>, <topic>, <version>
When a field list is the document body's first element [11], it may have its fields transformed to bibliographic data by the DocInfo transform. This bibliographic data corresponds to the front matter of a book, such as the title page and copyright page.
A document title, header and footer as well as elements that do not show up in the output before the bibliographic fields don't count. See PreBibliographic Elements for details.
Certain registered field names (listed below) are recognized and transformed to the corresponding doctree elements, most becoming child elements of the <docinfo> element. No ordering is required of these fields, although they may be rearranged to fit the document structure, as noted. Unless otherwise indicated below, each of the bibliographic elements' field bodies may contain a single paragraph only. Field bodies may be checked for RCS keywords and cleaned up. Any unrecognized fields will remain as generic fields in the docinfo element.
The registered bibliographic field names and their corresponding doctree elements are as follows:
field name [12]
doctree element
Abstract
Address
Author
Authors
Contact
Copyright