Ultimate Guide to Markdown
This article offers a quick cheatsheet of basic Markdown syntax that can be used in Hugo content files.
This article is a shameless plug of many great articles and documentations, in order to consolidate a better markdown cheatsheet for my hugo blog endeavours.
Over the years I have found writing content in Markdown or reStructureText is way more time efficent as compared to writing html. WYSIWYG editors will help reduce the complexity of this task but they can result in not so good looking web pages.
Markdown is a better way to write HTML, without all the complexities and ugliness that usually accompanies it.
Some benefits that can be attributed to Markdown are:
- Markdown is simple to learn, with minimal extra characters, so it’s also quicker to write content.
- Less chance of errors when writing in Markdown.
- Produces valid XHTML output.
- Keeps the content and the visual display separate, so you cannot mess up the look of your site.
- Write in any text editor or Markdown application you like.
- Markdown is a joy to use!
John Gruber, the author of Markdown, puts it like this:
The overriding design goal for Markdown’s formatting syntax is to make it as readable as possible. The idea is that a Markdown-formatted document should be publishable as-is, as plain text, without looking like it’s been marked up with tags or formatting instructions. While Markdown’s syntax has been influenced by several existing text-to-HTML filters, the single biggest source of inspiration for Markdown’s syntax is the format of plain text email.
– John Gruber
Without further delay, let us go over the main elements of Markdown and what the resulting HTML looks like!
Headings
Headings from h2
through h6
are constructed with a #
for each level:
|
|
The HTML looks like this:
|
|
To add a custom heading ID, enclose the custom ID in curly braces on the same line as the heading:
|
|
The HTML looks like this:
|
|
Alternate Syntax
Alternatively, on the line below the text, add any number of == characters for heading level 1 or – characters for heading level 2.
|
|
The HTML looks like this:
|
|
Best Practices
Markdown applications don’t agree on how to handle missing blank lines between a heading and the surrounding paragraphs. For compatibility, separate paragraphs and headings with one or more blank lines.
✅ Recommended | ❌ Avoid |
---|---|
This is a paragraph. # Here’s the heading And this is another paragraph. |
This is a paragraph. # Here’s the heading And this is another paragraph. |
Paragraphs
To create paragraphs, use a blank line to separate one or more lines of text.
|
|
The HTML looks like this:
|
|
The rendered output looks like this:
I really like using Markdown.
I think I’ll use it to format all of my documents from now on.
Best Practices
Don’t indent paragraphs with spaces or tabs.
✅ Recommended | ❌ Avoid |
---|---|
Don’t put tabs or spaces in front of your paragraphs. Keep lines left-aligned like this. |
This can result in unexpected formatting problems. Don’t add tabs or spaces in front of paragraphs. |
Line Breaks
To create a line break (<br>), end a line with two or more spaces, and then type return.
|
|
The HTML looks like this:
|
|
The rendered output looks like this:
This is the first line.
And this is the second line.
Best Practices
You can use two or more spaces (referred to as “trailing whitespace”) for line breaks in nearly every Markdown application, but it’s controversial. It’s hard to see trailing whitespace in an editor, and many people accidentally or intentionally put two spaces after every sentence. For this reason, you may want to use something other than trailing whitespace for line breaks. Fortunately, there is another option supported by nearly every Markdown application: the <br> HTML tag.
For compatibility, use trailing white space or the <br> HTML tag at the end of the line.
There are two other options I don’t recommend using. CommonMark and a few other lightweight markup languages let you type a backslash () at the end of the line, but not all Markdown applications support this, so it isn’t a great option from a compatibility perspective. And at least a couple lightweight markup languages don’t require anything at the end of the line — just type return and they’ll create a line break.
✅ Recommended | ❌ Avoid |
---|---|
First line with two spaces after. And the next line. First line with the HTML tag after.<br> And the next line. |
First line with a backslash after.\ And the next line. First line with nothing after. And the next line. |
Comment
Comments should be HTML compatible.
|
|
Comment below should NOT be seen:
Horizontal Rules
The HTML <hr>
element is for creating a “thematic break” between paragraph-level elements.
In Markdown, you can create a <hr>
with any of the following:
___
: three consecutive underscores---
: three consecutive dashes***
: three consecutive asterisks
The rendered output looks like this:
Best Practices
✅ Recommended | ❌ Avoid |
---|---|
Try to put a blank line before… - - - …and after a horizontal rule. |
Without blank lines, this would be a heading. - - - Don’t do this! |
Body Copy
Body copy written as normal, plain text will be wrapped with <p></p>
tags in the rendered HTML.
So this body copy:
|
|
The HTML looks like this:
|
|
A line break can be done with one blank line.
Inline HTML
If you need a certain HTML tag (with a class) you can simply use HTML:
|
|
Emphasis
Bold
For emphasizing a snippet of text with a heavier font-weight.
The following snippet of text is rendered as bold text.
|
|
The HTML looks like this:
|
|
Best Practices
Markdown applications don’t agree on how to handle underscores in the middle of a word. For compatibility, use asterisks to bold the middle of a word for emphasis.
✅ Recommended | ❌ Avoid |
---|---|
Love**is**bold | Love__is__bold |
Italics
For emphasizing a snippet of text with italics.
The following snippet of text is rendered as italicized text.
|
|
The HTML looks like this:
|
|
Best Practices
Markdown applications don’t agree on how to handle underscores in the middle of a word. For compatibility, use asterisks to italicize the middle of a word for emphasis.
✅ Recommended | ❌ Avoid |
---|---|
Love*is*bold | Love_is_bold |
Strikethrough
In GFM you can do strikethroughs. You can strikethrough words by putting a horizontal line through the center of them. The result looks like this. This feature allows you to indicate that certain words are a mistake not meant for inclusion in the document. To strikethrough words, use two tilde symbols (~~) before and after the words.
|
|
The rendered output looks like this:
Strike through this text.
The HTML looks like this:
|
|
Combination
Bold, italics, and strikethrough can be used in combination.
|
|
The rendered output looks like this:
bold and italics
strikethrough and bold
strikethrough and italics
bold, italics and strikethrough
The HTML looks like this:
|
|
Blockquotes
For quoting blocks of content from another source within your document.
Add >
before any text you want to quote:
|
|
The rendered output looks like this:
Fusion Drive combines a hard drive with a flash storage (solid-state drive) and presents it as a single logical volume with the space of both drives combined.
The HTML looks like this:
|
|
Blockquotes with Multiple Paragraphs
Blockquotes can contain multiple paragraphs. Add a > on the blank lines between the paragraphs.
|
|
The rendered output looks like this:
Dorothy followed her through many of the beautiful rooms in her castle.
The Witch bade her clean the pots and kettles and sweep the floor and keep the fire fed with wood.
Nested Blockquotes
Blockquotes can be nested. Add a » in front of the paragraph you want to nest.
|
|
The rendered output looks like this:
Donec massa lacus, ultricies a ullamcorper in, fermentum sed augue. Nunc augue augue, aliquam non hendrerit ac, commodo vel nisi.
Sed adipiscing elit vitae augue consectetur a gravida nunc vehicula. Donec auctor odio non est accumsan facilisis. Aliquam id turpis in dolor tincidunt mollis ac eu diam.
Blockquotes with Other Elements
Blockquotes can contain other Markdown formatted elements. Not all elements can be used — you’ll need to experiment to see which ones work.
|
|
The rendered output looks like this:
The quarterly results look great!
- Revenue was off the chart.
- Profits were higher than ever.
Everything is going according to plan.
Lists
Unordered
A list of items in which the order of the items does not explicitly matter.
You may use any of the following symbols to denote bullets for each list item:
|
|
For example:
|
|
The rendered output looks like this:
- Lorem ipsum dolor sit amet
- Consectetur adipiscing elit
- Integer molestie lorem at massa
- Facilisis in pretium nisl aliquet
- Nulla volutpat aliquam velit
- Phasellus iaculis neque
- Purus sodales ultricies
- Vestibulum laoreet porttitor sem
- Ac tristique libero volutpat at
- Faucibus porta lacus fringilla vel
- Aenean sit amet erat nunc
- Eget porttitor lorem
The HTML looks like this:
|
|
Ordered
A list of items in which the order of items does explicitly matter.
|
|
The rendered output looks like this:
- Lorem ipsum dolor sit amet
- Consectetur adipiscing elit
- Integer molestie lorem at massa
- Facilisis in pretium nisl aliquet
- Nulla volutpat aliquam velit
- Faucibus porta lacus fringilla vel
- Aenean sit amet erat nunc
- Eget porttitor lorem
The HTML looks like this:
|
|
If you just use 1.
for each number, Markdown will automatically number each item. For example:
|
|
The rendered output looks like this:
- Lorem ipsum dolor sit amet
- Consectetur adipiscing elit
- Integer molestie lorem at massa
- Facilisis in pretium nisl aliquet
- Nulla volutpat aliquam velit
- Faucibus porta lacus fringilla vel
- Aenean sit amet erat nunc
- Eget porttitor lorem
Task Lists
Task lists allow you to create a list of items with checkboxes. To create a task list, add dashes (-
) and brackets with a space ([ ]
) before task list items. To select a checkbox, add an x in between the brackets ([x]
).
|
|
The rendered output looks like this:
- Write the press release
- Update the website
- Contact the media
Definition Lists
Some Markdown processors allow you to create definition lists of terms and their corresponding definitions. To create a definition list, type the term on the first line. On the next line, type a colon followed by a space and the definition.
|
|
The HTML looks like this:
|
|
The rendered output looks like this:
- First Term
- This is the definition of the first term.
- Second Term
- This is one definition of the second term.
- This is another definition of the second term.
Adding Elements in Lists
To add another element in a list while preserving the continuity of the list, indent the element four spaces or one tab, as shown in the following examples.
Paragraphs
|
|
-
This is the first list item.
-
Here’s the second list item.
I need to add another paragraph below the second list item.
-
And here’s the third list item.
Blockquotes
|
|
The rendered output looks like this:
-
This is the first list item.
-
Here’s the second list item.
A blockquote would look great below the second list item.
-
And here’s the third list item.
Code
Inline Code
Wrap inline snippets of code with backticks `
.
|
|
The rendered output looks like this:
In this example, <section></section>
should be wrapped as code.
The HTML looks like this:
|
|
Indented Code
Or indent several lines of code by at least four spaces, as in:
|
|
The rendered output looks like this:
// Some comments
line 1 of code
line 2 of code
line 3 of code
The HTML looks like this:
|
|
Block Fenced Code
Use “fences” ```
to block in multiple lines of code with a language attribute.
|
|
The HTML looks like this:
|
|
Syntax Highlighting
GFM also supports syntax highlighting.
To activate it, simply add the file extension of the language you want to use directly after the first code “fence”,
```js
, and syntax highlighting will automatically be applied in the rendered HTML.
For example, to apply syntax highlighting to JavaScript code:
|
|
The rendered output looks like this:
|
|
Tables
Tables are created by adding pipes as dividers between each cell, and by adding a line of dashes (also separated by bars) beneath the header. Note that the pipes do not need to be vertically aligned.
|
|
The rendered output looks like this:
Option | Description |
---|---|
data | path to data files to supply the data that will be passed into templates. |
engine | engine to be used for processing templates. Handlebars is the default. |
ext | extension to be used for dest files. |
The HTML looks like this:
|
|
Adding a colon on the right side of the dashes below any heading will right align text for that column.
Adding colons on both sides of the dashes below any heading will center align text for that column.
|
|
The rendered output looks like this:
Option | Description |
---|---|
data | path to data files to supply the data that will be passed into templates. |
engine | engine to be used for processing templates. Handlebars is the default. |
ext | extension to be used for dest files. |
Formatting Text in Tables
You can format the text within tables. For example, you can add links, code (words or phrases in backticks (`) only, not code blocks and emphasis.
You can’t add headings, blockquotes, lists, horizontal rules, images, or HTML tags.
Escaping Pipe Characters in Tables
You can display a pipe (|) character in a table by using its HTML character code (|).
Links
Basic Link
To quickly turn a URL or email address into a link, enclose it in angle brackets. To create a link, enclose the link text in brackets (e.g., [Duck Duck Go]) and then follow it immediately with the URL in parentheses (e.g., (https://duckduckgo.com)).
|
|
The rendered output looks like this (hover over the link, there is no tooltip):
The HTML looks like this:
|
|
Add a Title
|
|
The rendered output looks like this (hover over the link, there should be a tooltip):
The HTML looks like this:
|
|
Named Anchors
Named anchors enable you to jump to the specified anchor point on the same page. For example, each of these chapters:
|
|
will jump to these sections:
|
|
Formatting Links
To emphasize links, add asterisks before and after the brackets and parentheses. To denote links as code, add backticks in the brackets.
|
|
I love supporting the EFF.
This is the Markdown Guide.
See the section on code
.
The rendered output looks like this:
Automatic URL Linking
Many Markdown processors automatically turn URLs into links. That means if you type http://www.example.com, your Markdown processor will automatically turn it into a link even though you haven’t used brackets.
|
|
The rendered output looks like this:
Disabling Automatic URL Linking
If you don’t want a URL to be automatically linked, you can remove the link by denoting the URL as code with backticks.
|
|
The rendered output looks like this:
http://www.example.com
Best Practices
Markdown applications don’t agree on how to handle spaces in the middle of a URL. For compatibility, try to URL encode any spaces with %20.
✅ Recommended | ❌ Avoid |
---|---|
[link](https://www.example.com/my%20great%20page) | [link](https://www.example.com/my great page) |
Images
Images have a similar syntax to links but include a preceding exclamation point.
|
|
or:
|
|
Like links, images also have a footnote style syntax:
|
|
With a reference later in the document defining the URL location:
|
|
Who knew there was a way to do gifs as well.
|
|
Emoji
There are two ways to add emoji to Markdown files: copy and paste the emoji into your Markdown-formatted text, or type emoji shortcodes.
Copying and Pasting Emoji
In most cases, you can simply copy an emoji from a source like Emojipedia and paste it into your document. Many Markdown applications will automatically display the emoji in the Markdown-formatted text. The HTML and PDF files you export from your Markdown application should display the emoji.
Using Emoji Shortcodes
Some Markdown applications allow you to insert emoji by typing emoji shortcodes. These begin and end with a colon and include the name of an emoji.
|
|
The rendered output looks like this:
Gone camping! ⛺ Be back soon.
That is so funny! 😂
Footnotes
Footnotes allow you to add notes and references without cluttering the body of the document. When you create a footnote, a superscript number with a link appears where you added the footnote reference. Readers can click the link to jump to the content of the footnote at the bottom of the page.
To create a footnote reference, add a caret and an identifier inside brackets ([^1]
). Identifiers can be numbers or words, but they can’t contain spaces or tabs. Identifiers only correlate the footnote reference with the footnote itself — in the output, footnotes are numbered sequentially.
Add the footnote using another caret and number inside brackets with a colon and text ([^1]: My footnote.
). You don’t have to put footnotes at the end of the document. You can put them anywhere except inside other elements like lists, block quotes, and tables.
|
|
The rendered output looks like this:
This is a digital footnote1. This is a footnote with “label”2 and here’s a longer one.3