Mnemonic for Markdown's link syntax (and image syntax)

Published on in Markdown and Mnemonics

Last updated on

Was it [text](url) or (text)[url]? Use this one weird trick to remember – Markdown consultants HATE it! Spoiler: it's the former since it looks like a function call.

Table of contents

The first part looks like an array of words: [link text].

The second part looks like it's used to call a function with one parameter: (url).

Put together:

[I'm an array of words](/and-im-a-parameter-to-a-function-call)

[Link text with **bold words**](

Optional second parameter

Thinking of functions, you can also provide a title as the second parameter. These are all valid and identical (according to the CommonMark Spec):

[Link text](/some-url "And a title")
[Link text](/some-url 'And a title')
[Link text](/some-url (And a title))

Output (×3):

<a href="/some-url" title="And a title">Link text</a>

The title attribute is not very accessible, so you shouldn't rely on it too much.


(link text)[url] would look like you are using the url key to access a value from... hmm, from the expression (link text), which isn't even a valid expression? That wouldn't make as much sense.

For completeness, let's see other ways of specifying links in Markdown. Reference links are also related to Markdown's image syntax.

These are simple: wrap an absolute URI or an email address in angle brackets.




<a href=""></a>
<a href=""></a>

A reference link consists of link text and a link label.

The link label should have a corresponding "link reference definition" somewhere in the document, for example at the end of a section or at the end of the whole document. Link labels are case-insensitive.


Check out [foo][1], [bar][2] and [baz][3].


Do you know what's [my favorite search engine][duck]?
I like it more than [Microsoft's search engine][bing].



Check out
<a href="">foo</a>,
<a href="">bar</a> and
<a href="">baz</a>.

Do you know what's <a href="">my favorite search engine</a>?
I like it more than <a href="">Microsoft's search engine</a>.

Collapsed reference links

If the link text and label are the same (labels are case-insensitive), you can use "collapsed reference links" and drop the label:

Check out [foo][], [Bar][] and [BAZ & qux][].

[baz & qux]:

Shortcut reference links

"Shortcut reference links" take a step further by allowing you to drop the empty brackets as well:

Check out [foo], [Bar] and [BAZ & qux].

[baz & qux]:

The image syntax is the same as the link syntax, except that there's a bang (!) at the beginning, and the link text is the image's alt text:

![A nice pic](/image-url)
![A nice pic][a nice pic]
![A nice pic][]
![A nice pic]

[a nice pic]: /image-url

Output (×4):

<img src="/image-url" alt="A nice pic" />

Omitting the alt text produces alt="":

![][a nice pic]

[a nice pic]: /image-url

Output (×2):

<img src="/image-url" alt="" />

Nothing special; just the same link syntax where the link text is an image:

[![A nice pic](/image-url)](/link-url)
[![A nice pic][a nice pic]](/link-url)
[![A nice pic][]](/link-url)
[![A nice pic]](/link-url)

[![A nice pic](/image-url)][some page]
[![A nice pic][a nice pic]][some page]
[![A nice pic][]][some page]
[![A nice pic]][some page]

[a nice pic]: /image-url
[some page]: /link-url

Huh, quite busy syntax.

Output (×8):

<a href="/link-url">
  <img src="/image-url" alt="A nice pic" />

Further resources

The CommonMark Spec has more examples and edge cases covered. Check out these sections of the spec: