Links and media
We have seen most markdown syntaxes so far. To jog your memory these were headings at six levels, italics, bold, two types of unordered lists, two types of ordered lists, horizontal rules and blockquotes.
In this lesson we will discuss two other important, and related, markdown codes: links and media. Observe how in both cases you will have nearly identical markdown codes -- with just one extra character -- because these are identical in spirit. They link to (and display) something from somewhere else.
File systems
Since plain text files are the fundamental building blocks in a file system, we will sometimes need to pay attention to the organisational structure of our file system too. We will discuss this in detail in a future lesson but for now imagine we are working with files laid out in this manner:
.
└── Main-folder/
├── Images/
│ └── image-two.png
├── Documents/
│ ├── current-document.txt
│ ├── another-document.txt
│ └── image-one.png
└── links.txt
Let us assume, for this lesson, that we will be writing in the file called current-document.txt located within the Main-folder/Documents/ subfolder on my computer.
Direct links
The markdown syntax for a link is quite simple but its unusual structure can understandably become confusing for beginners. It looks like this:
[Link text](link)
The confusion arises with the brackets as you may find yourself wondering if the order is ()[] or []() but there is a simple way to remember this: you are writing a ‘Link’ and the word ‘Link’ starts with an L which looks like part of a square backet [ so that is how the markdown for a link starts as well.
But a second confusion quickly comes knocking: the order is settled as []() but what goes inside each bracket, is it a link followed by some text or the other way round? The way to remember this is to ask yourself which of these phrases sounds natural when you write:
Visit this link: <link>
or
<link> visit this link
Clearly the first one sounds more natural. Indeed that is how markdown sounds as well: [Visit](this link).
In the [next lesson](/lessons/tables) you will
learn all about markdown tables.
Which, when processed, looks like this:
In the next lesson you will learn all about markdown tables.
Relative Links
Notice how my link in the example above starts with a forward slash. That is because it is a link relative to this website. If I wanted to link to, say, the Internet Archive, I would write
[visit the Internet Archive](https://web.archive.org)
and we know exactly what that would look like.
The same would go for any file I might want to link to. Recall our file tree from earlier; we said we are working in current-document.txt so if we typed this:
For more info, please read [another file](another-document.txt)
The words another file would now link to the file called another-document.txt which is at the same level as current-document.txt.
But what if I want to link instead to links.txt? That is to say, my link source and link destination would be these:
source : Main-folder/Documents/current-document.txt
destination : Main-folder/links.txt
Since we are currently in the Documents/ folder and need to go one level up to the Main-folder to access links.txt we make use of the symbol ../ which means go up one level.
Next, check out [our links](../links.txt)
Reference-style links
Sometimes we may have a link that is used multiple times in a file. Consider this paragraph:
In Saxon times our schools of learning were grouped round York
the [Roman](https://romearound.it) centre of Britain,
which represented not only the [Roman](https://romearound.it)
tradition but the vigorous…
Note how the same link appears twice in this paragraph. We can simplify this using what are called reference-style links. Rather than writing a link twice, we assign it a number -- any integral number -- and then assign a link to that number instead.
In Saxon times our schools of learning were grouped round York
the [Roman][1] centre of Britain, which represented not only
the [Roman][1] tradition but the vigorous…
[1]: https://romearound.it
The great benefit of reference links is that if you later find that romearound.it is closed -- or worse, wrong -- and you want to replace it with a new link, you just need to replace it once.
In Saxon times our schools of learning were grouped round York the Roman centre of Britain, which represented not only the Roman tradition but the vigorous…
Why these are called ‘reference-style’ links will become clear to you in a later lesson when we discuss actual references. (Spoiler alert: they are almost identical.)
You can also simply type a link without any markup and most editors will interpret them as links. It used to be that bare links would be enclosed within inequality signs <...> but this is not always necessary except as an added marker.
Images
Markdown views images as previews of links to external files. It therefore uses the ! character in addition to a standard link. That is to say, you an add image to a markdown file using

Let us return to our file tree to understand this better. Say we want to add image-one.png to our current-document.txt, we can do so with just the file name and the ‘png‘ extension:

But to add image-two.png from the neighbouring folder, we need to go up one level using ../ then into the Images folder and then specify the filename and extension.

Would an image show up in a text file? Not quite. In many editors you would just see the line of text as above. But many others have a feature where they preview the image. But this is merely a visual change on the editor; the text file is still very much all text. The image markup is intended for conversions of this plain text file into something else, in which case the image will indeed show up.
The text in the square brackets is technically optional, so you could get away with just  and the image will work just fine. However, this is strongly discouraged since it outputs blank alt text making for poor accessibility for people who might not be able to see your image.
In addition, should your image file become corrupt, get misplaced, or simply be incorrectly spelt or located, the alt text will at least describe to the reader what should have been there. Some programmes even use alt texts as captions.
How about audio and video?
Markdown does not support either audio or video natively. You can embed HTML of course, or simply link to the files, but do not expect any media to actually play in a markdown file. As a reminder, this is all still plain text.
Most people store such files next to the text file and link from the text file so that clicking on that link will play the media file in whatever the default player is. Some apps offer special media ‘previews’ but such features are not part of a plain text file or of markdown.
TIP While this is not necessary, and while adding a link to an image file within the same folder is more straightforward, maintaining a dedicated media folder (like Images in our example) can make it easier to manage assets, and is the recommended approach especially if you expect your image files to grow in number over time. While you are at it, also consider your file naming schemes.