4.7Link reference definitions
A link reference definition
consists of a link label, optionally preceded by up to three spaces of
indentation, followed
by a colon (:), optional spaces or tabs (including up to one
line ending), a link destination,
optional spaces or tabs (including up to one
line ending), and an optional link
title, which if it is present must be separated
from the link destination by spaces or tabs.
No further character may occur.
A link reference definition does not correspond to a structural element of a document. Instead, it defines a label which can be used in reference links and reference-style images elsewhere in the document. Link reference definitions can come either before or after the links that use them.
[Foo*bar\]]:my_(url) 'title (with parens)'
[Foo*bar\]]
<p><a href="my_(url)" title="title (with parens)">Foo*bar]</a></p>
[Foo bar]:
<my url>
'title'
[Foo bar]
<p><a href="my%20url" title="title">Foo bar</a></p>
The title may extend over multiple lines:
[foo]: /url '
title
line1
line2
'
[foo]
<p><a href="/url" title="
title
line1
line2
">foo</a></p>
However, it may not contain a blank line:
[foo]: /url 'title
with blank line'
[foo]
<p>[foo]: /url 'title</p>
<p>with blank line'</p>
<p>[foo]</p>
The title may be omitted:
The link destination may not be omitted:
However, an empty link destination may be specified using angle brackets:
The title must be separated from the link destination by spaces or tabs:
Both title and destination can contain backslash escapes and literal backslashes:
[foo]: /url\bar\*baz "foo\"bar\baz"
[foo]
<p><a href="/url%5Cbar*baz" title="foo"bar\baz">foo</a></p>
A link can come before its corresponding definition:
If there are several matching definitions, the first one takes precedence:
As noted in the section on Links, matching of labels is case-insensitive (see matches).
Whether something is a link reference definition is independent of whether the link reference it defines is used in the document. Thus, for example, the following document contains just a link reference definition, and no visible content:
Here is another one:
This is not a link reference definition, because there are characters other than spaces or tabs after the title:
This is a link reference definition, but it has no title:
This is not a link reference definition, because it is indented four spaces:
[foo]: /url "title"
[foo]
<pre><code>[foo]: /url "title"
</code></pre>
<p>[foo]</p>
This is not a link reference definition, because it occurs inside a code block:
A link reference definition cannot interrupt a paragraph.
However, it can directly follow other block elements, such as headings and thematic breaks, and it need not be followed by a blank line.
# [Foo]
[foo]: /url
> bar
<h1><a href="/url">Foo</a></h1>
<blockquote>
<p>bar</p>
</blockquote>
Several link reference definitions can occur one after another, without intervening blank lines.
[foo]: /foo-url "foo"
[bar]: /bar-url
"bar"
[baz]: /baz-url
[foo],
[bar],
[baz]
<p><a href="/foo-url" title="foo">foo</a>,
<a href="/bar-url" title="bar">bar</a>,
<a href="/baz-url">baz</a></p>
Link reference definitions can occur inside block containers, like lists and block quotations. They affect the entire document, not just the container in which they are defined: