Most developers will encounter Markdown files at some stage of their careers, via repository platforms such as GitHub or Bitbucket. Markdown files use the
.md file extension and will contain specific syntax used to construct the file. Many content management systems and frameworks support markdown out the box, so to start using it is as simple as creating a file and adding its content.
Markdown files are extremely powerful because it allows the creator the ability to easily construct beautiful and semantic markup without having to build it with code. They are often used inside git repositories as documentation but have also grown to be extremely popular on blogging platforms. I personally store my posts on GitHub which Hugo then turns into semantic HTML.
In this tutorial, I will cover some basic syntax used inside Markdown files which will allow you to start creating beautifully structured content.
Headings will be represented by adding a # symbol before the title. The number of # symbols signifies the order of importance, so by adding a single # it will represent a
<h1> tag. Adding additional # symbols will decrease the order of importance with the number of symbols indicating the appropriate
1# Heading 1 <h1>2## Heading 2 <h2>3### Heading 3 <h3>4#### Heading 4 <h4>5##### Heading 5 <h5>6###### Heading 6 <h6>
There is no specific syntax used when writing paragraphs in markdown syntax. Paragraphs can be created by adding one or more blank lines:
1I am a paragraph.23I am another paragraph.
When adding headings and paragraphs, make sure they are all separated by a new line and are not on top of each other.
Line breaks are similar to paragraphs except instead of a single blank line you will add two blank lines to signify a line break.
1I am a paragraph with a line break below me.23I am a paragraph with a line break above me.
As we go further into this tutorial, you will find that there are many ways to achieve the same result. For example, bold text can be added to a document in the following ways:
**Bold text** will render Bold text
__Bold text__ will render Bold text
The syntax for italic text is similar to that of bold text. A single asterisk or underscore will be used on either side of the text or phrase.
*Italic text* will render: Italic text
_Italic text_ will render: Italic text
Lists have varying syntax.
To create ordered lists, simply add items with numbers followed by a period. Each list item will need to be on a new line.
11. Ordered list item #122. Ordered list item #233. Ordered list item #3
They do not need to be in numerical order:
11. Ordered list item #123. Ordered list item #332. Ordered list item #2
You may also nest lists:
11. Ordered list item #122. Ordered list item #233. Ordered list item #34 1. Ordered nested list item #15 2. Ordered nested list item #2
To create an unordered list, simply add either a dash (-), asterisk (*), or plus signs (+) in front of your line items.
1- Unordered list item #12- Unordered list item #23- Unordered list item #3
Much like the ordered list, the same principle applies when nesting unordered lists.
1- Unordered list item #12- Unordered list item #23- Unordered list item #34 - Unordered nested list item #15 - Unordered nested list item #26 - Unordered nested list item #3
To create a link, enclose the text you wish to link with square brackets followed by the link in parentheses.
If you would like to add a title to the link, you would add the following:
1[example.com](https://example.com/ "Link title")
Links can also be created by adding a chevron on either side of the link:
Using the above syntax is especially useful for email addresses:
Images have a similar syntax to links, except they have an exclamation mark in front of the square brackets, followed by the alt text inside the square brackets and the path to the image in parentheses.
Much like links a title can also be added to an image by adding the following:
1![I am the alt text](/assets/images/image-2.jpg "Image title")
A blockquote can be created by adding a right-facing chevron
> in front of a paragraph.
1> I am a blockquote
Using this syntax will render the following:
I am a blockquote
Code blocks can be added to markdown files by enclosing the word, phrase or code with backticks. (``)
1`A code block using backticks`
Alternatively you may create code blocks by indenting by at least four spaces or with one tab:
1A code block created using four spaces or one tab.
There are a number of ways to add a horizontal rule to a document by either adding three or more asterisks (***), dashes or underscores:
Any of the above will render:
Some Markdown applications or frameworks allow you to insert HTML tags into the file. This is useful if you would like to use certain HTML tags instead of Markdown syntax. Using this approach it is much easier to change the attributes of an element.
1I am using regular **bold** syntax with an HTML link <a href="#" class="text-blue-100">Link</a>
As you can see Markdown is extremely powerful and user-friendly, it has many benefits and provides creators with an easy way to create beautifully structured content. It is a huge time saver and allows you to focus on what truly matters most, your content.