2013-08-13 01:57:23 +04:00
---
language: markdown
contributors:
- ["Dan Turkel", "http://danturkel.com/"]
2015-11-01 06:02:18 +03:00
- ["Jacob Ward", "http://github.com/JacobCWard/"]
2021-11-27 23:19:54 +03:00
- ["Tomáš Hartman", "https://github.com/tomas-hartman"]
2013-08-13 01:57:23 +04:00
filename: markdown.md
---
2015-10-30 18:24:49 +03:00
2021-11-27 23:19:54 +03:00
Markdown was created by John Gruber in 2004. It's meant to be an easy to read
and write syntax which converts easily to HTML (and now many other formats as
2016-03-18 10:01:55 +03:00
well).
2015-10-30 18:24:49 +03:00
2015-11-01 06:02:18 +03:00
Markdown also varies in implementation from one parser to a next. This
2014-05-12 04:14:07 +04:00
guide will attempt to clarify when features are universal or when they are
2015-11-01 06:02:18 +03:00
specific to a certain parser.
2015-11-02 18:11:50 +03:00
- [HTML Elements ](#html-elements )
2015-11-01 06:02:18 +03:00
- [Headings ](#headings )
2021-11-27 23:19:54 +03:00
- [Simple text styles ](#simple-text-styles )
2015-11-01 06:09:58 +03:00
- [Paragraphs ](#paragraphs )
- [Lists ](#lists )
- [Code blocks ](#code-blocks )
- [Horizontal rule ](#horizontal-rule )
- [Links ](#links )
2021-11-27 23:19:54 +03:00
- [Table of contents ](#table-of-contents )
2015-11-01 06:09:58 +03:00
- [Images ](#images )
- [Miscellany ](#miscellany )
2021-11-27 23:19:54 +03:00
- [Auto-links ](#auto-links )
- [Auto-links for emails ](#auto-links-for-emails )
- [Escaping characters ](#escaping-characters )
- [Keyboard keys ](#keyboard-keys )
- [Tables ](#tables )
- [Markdownlint ](#markdownlint )
- [Further reading ](#further-reading )
2015-11-01 06:02:18 +03:00
2015-11-02 18:11:50 +03:00
## HTML Elements
2021-11-27 23:19:54 +03:00
2015-11-02 18:11:50 +03:00
Markdown is a superset of HTML, so any HTML file is valid Markdown.
2016-01-08 09:35:16 +03:00
2018-03-05 06:48:44 +03:00
```md
2022-11-11 12:38:32 +03:00
<!-- This means we can use HTML elements in Markdown, such as the comment
element, and they won't be affected by a markdown parser. However, if you
create an HTML element in your markdown file, you cannot use markdown syntax
2016-03-18 10:01:55 +03:00
within that element's contents.-->
2015-11-02 18:11:50 +03:00
```
2015-11-01 06:02:18 +03:00
## Headings
2013-08-13 01:57:23 +04:00
2015-11-01 06:02:18 +03:00
You can create HTML elements `<h1>` through `<h6>` easily by prepending the
text you want to be in that element by a number of hashes (#).
2018-03-05 06:48:44 +03:00
```md
2013-08-13 01:57:23 +04:00
# This is an <h1>
## This is an <h2>
### This is an <h3>
#### This is an <h4>
##### This is an <h5>
###### This is an <h6>
2015-11-01 06:02:18 +03:00
```
2021-11-27 23:19:54 +03:00
2015-11-01 06:02:18 +03:00
Markdown also provides us with two alternative ways of indicating h1 and h2.
2013-08-13 01:57:23 +04:00
2018-03-05 06:48:44 +03:00
```md
2013-08-13 01:57:23 +04:00
This is an h1
=============
This is an h2
-------------
2015-11-01 06:02:18 +03:00
```
2016-01-08 09:35:16 +03:00
2015-11-01 06:02:18 +03:00
## Simple text styles
2014-05-12 04:14:07 +04:00
2015-11-01 06:02:18 +03:00
Text can be easily styled as italic or bold using markdown.
2013-08-13 01:57:23 +04:00
2018-03-05 06:48:44 +03:00
```md
2013-08-13 01:57:23 +04:00
*This text is in italics.*
_And so is this text._
**This text is in bold.**
__And so is this text.__
***This text is in both.***
**_As is this!_**
*__And this!__*
2015-11-01 06:02:18 +03:00
```
2013-08-13 01:57:23 +04:00
2016-02-24 03:12:44 +03:00
In GitHub Flavored Markdown, which is used to render markdown files on
GitHub, we also have strikethrough:
2015-10-30 18:24:49 +03:00
2018-03-05 06:48:44 +03:00
```md
2013-08-13 01:57:23 +04:00
~~This text is rendered with strikethrough.~~
2015-11-01 06:02:18 +03:00
```
2021-11-27 23:19:54 +03:00
2015-11-01 06:02:18 +03:00
## Paragraphs
2013-08-13 01:57:23 +04:00
2015-11-01 06:02:18 +03:00
Paragraphs are a one or multiple adjacent lines of text separated by one or
multiple blank lines.
2013-08-13 01:57:23 +04:00
2018-03-05 06:48:44 +03:00
```md
2014-06-12 01:36:16 +04:00
This is a paragraph. I'm typing in a paragraph isn't this fun?
2013-08-13 01:57:23 +04:00
Now I'm in paragraph 2.
I'm still in paragraph 2 too!
I'm in paragraph three!
2015-11-01 06:02:18 +03:00
```
2013-08-13 01:57:23 +04:00
2016-10-04 16:41:21 +03:00
Should you ever want to insert an HTML `<br />` tag, you can end a paragraph
2015-11-01 06:02:18 +03:00
with two or more spaces and then begin a new paragraph.
2013-08-13 01:57:23 +04:00
2018-03-05 06:48:44 +03:00
```md
2015-10-08 06:11:24 +03:00
I end with two spaces (highlight me to see them).
2013-08-13 01:57:23 +04:00
There's a < br / > above me!
2015-11-01 06:02:18 +03:00
```
2013-08-13 01:57:23 +04:00
2015-11-01 06:02:18 +03:00
Block quotes are easy and done with the > character.
2013-08-13 01:57:23 +04:00
2018-03-05 06:48:44 +03:00
```md
2013-08-13 01:57:23 +04:00
> This is a block quote. You can either
2014-05-12 04:14:07 +04:00
> manually wrap your lines and put a `>` before every line or you can let your lines get really long and wrap on their own.
> It doesn't make a difference so long as they start with a `>`.
2013-08-13 01:57:23 +04:00
> You can also use more than one level
>> of indentation?
> How neat is that?
2015-11-01 06:02:18 +03:00
```
## Lists
2021-11-27 23:19:54 +03:00
2015-11-01 06:02:18 +03:00
Unordered lists can be made using asterisks, pluses, or hyphens.
2013-08-13 01:57:23 +04:00
2018-03-05 06:48:44 +03:00
```md
2013-08-13 01:57:23 +04:00
* Item
* Item
* Another item
or
+ Item
+ Item
+ One more item
2015-10-08 06:11:24 +03:00
or
2013-08-13 01:57:23 +04:00
- Item
- Item
- One last item
2015-11-01 06:02:18 +03:00
```
2016-01-08 09:35:16 +03:00
2015-11-01 06:02:18 +03:00
Ordered lists are done with a number followed by a period.
2013-08-13 01:57:23 +04:00
2018-03-05 06:48:44 +03:00
```md
2013-08-13 01:57:23 +04:00
1. Item one
2. Item two
3. Item three
2015-11-01 06:02:18 +03:00
```
2013-08-13 01:57:23 +04:00
2016-10-04 16:41:21 +03:00
You don't even have to label the items correctly and Markdown will still
2015-11-01 06:02:18 +03:00
render the numbers in order, but this may not be a good idea.
2013-08-13 01:57:23 +04:00
2018-03-05 06:48:44 +03:00
```md
2013-08-13 01:57:23 +04:00
1. Item one
1. Item two
1. Item three
2015-11-01 06:02:18 +03:00
```
2021-11-27 23:19:54 +03:00
2022-01-16 06:43:14 +03:00
(This renders the same as the example above.)
2013-08-13 01:57:23 +04:00
2022-01-16 06:43:14 +03:00
You can also use sublists.
2016-01-08 09:35:16 +03:00
2018-03-05 06:48:44 +03:00
```md
2013-08-13 01:57:23 +04:00
1. Item one
2. Item two
3. Item three
* Sub-item
* Sub-item
4. Item four
2015-11-01 06:02:18 +03:00
```
2013-08-13 01:57:23 +04:00
2015-11-01 06:02:18 +03:00
There are even task lists. This creates HTML checkboxes.
2014-10-18 06:09:51 +04:00
2018-03-05 06:48:44 +03:00
```md
2014-10-18 06:09:51 +04:00
Boxes below without the 'x' are unchecked HTML checkboxes.
2015-10-08 06:11:24 +03:00
- [ ] First task to complete.
2014-10-18 06:09:51 +04:00
- [ ] Second task that needs done
This checkbox below will be a checked HTML checkbox.
- [x] This task has been completed
2015-11-01 06:02:18 +03:00
```
## Code blocks
2014-10-18 06:09:51 +04:00
2015-11-01 06:02:18 +03:00
You can indicate a code block (which uses the `<code>` element) by indenting
a line with four spaces or a tab.
2013-08-13 01:57:23 +04:00
2018-03-05 06:48:44 +03:00
```md
2013-08-13 01:57:23 +04:00
This is code
So is this
2015-11-01 06:02:18 +03:00
```
2013-08-13 01:57:23 +04:00
2015-11-01 06:02:18 +03:00
You can also re-tab (or add an additional four spaces) for indentation
2022-01-16 06:43:14 +03:00
inside your code.
2013-08-13 01:57:23 +04:00
2018-03-05 06:48:44 +03:00
```md
2013-08-13 01:57:23 +04:00
my_array.each do |item|
puts item
end
2015-11-01 06:02:18 +03:00
```
2013-08-13 01:57:23 +04:00
2022-01-16 06:43:14 +03:00
Inline code can be created using the backtick character `` ` ` `.
2013-08-13 01:57:23 +04:00
2018-03-05 06:48:44 +03:00
```md
2013-08-13 01:57:23 +04:00
John didn't even know what the `go_to()` function did!
2015-11-01 06:02:18 +03:00
```
2013-08-13 01:57:23 +04:00
2022-01-16 06:43:14 +03:00
In GitHub Flavored Markdown, you can use a special syntax for code.
2016-01-08 09:35:16 +03:00
< pre >
< code class = "highlight" > ` ` ` ruby
2013-08-13 01:57:23 +04:00
def foobar
puts "Hello world!"
end
2016-01-08 09:35:16 +03:00
` ` ` < / code > < / pre >
2013-08-13 01:57:23 +04:00
2016-02-24 03:12:44 +03:00
The above text doesn't require indenting, plus GitHub will use syntax
2022-01-16 06:43:14 +03:00
highlighting of the language you specify after the opening < code > ```< / code > .
2013-08-13 01:57:23 +04:00
2015-11-01 06:09:58 +03:00
## Horizontal rule
2013-08-13 01:57:23 +04:00
2021-11-27 23:19:54 +03:00
Horizontal rules (`< hr / > `) are easily added with three or more asterisks or
2016-03-18 10:01:55 +03:00
hyphens, with or without spaces.
2016-01-08 09:35:16 +03:00
2018-03-05 06:48:44 +03:00
```md
2013-08-13 01:57:23 +04:00
***
---
2015-10-08 06:11:24 +03:00
- - -
2013-08-13 01:57:23 +04:00
****************
2015-11-01 06:02:18 +03:00
```
2013-08-13 01:57:23 +04:00
2015-11-01 06:02:18 +03:00
## Links
2013-08-13 01:57:23 +04:00
2015-11-01 06:02:18 +03:00
One of the best things about markdown is how easy it is to make links. Put
the text to display in hard brackets [] followed by the url in parentheses ()
2013-08-13 01:57:23 +04:00
2018-03-05 06:48:44 +03:00
```md
2015-11-01 06:02:18 +03:00
[Click me! ](http://test.com/ )
```
2021-11-27 23:19:54 +03:00
2015-11-01 06:02:18 +03:00
You can also add a link title using quotes inside the parentheses.
2016-01-08 09:35:16 +03:00
2018-03-05 06:48:44 +03:00
```md
2013-08-13 01:57:23 +04:00
[Click me! ](http://test.com/ "Link to Test.com" )
2015-11-01 06:02:18 +03:00
```
2021-11-27 23:19:54 +03:00
2015-11-01 06:02:18 +03:00
Relative paths work too.
2016-01-08 09:35:16 +03:00
2018-03-05 06:48:44 +03:00
```md
2013-08-13 01:57:23 +04:00
[Go to music ](/music/ ).
2015-11-01 06:02:18 +03:00
```
2016-01-08 09:35:16 +03:00
2015-11-01 06:02:18 +03:00
Markdown also supports reference style links.
2013-08-13 01:57:23 +04:00
2016-01-08 09:35:16 +03:00
< pre > < code class = "highlight" > [ < span class = "nv" > Click this link< / span > ][< span class = "ss" > link1< / span > ] for more info about it!
[ < span class = "nv" > Also check out this link< / span > ][< span class = "ss" > foobar< / span > ] if you want to.
[ < span class = "nv" > link1< / span > ]: < span class = "sx" > http://test.com/< / span > < span class = "nn" > "Cool!"< / span >
[ < span class = "nv" > foobar< / span > ]: < span class = "sx" > http://foobar.biz/< / span > < span class = "nn" > "Alright!"< / span > < / code > < / pre >
2015-11-01 06:02:18 +03:00
The title can also be in single quotes or in parentheses, or omitted
2014-05-12 04:14:07 +04:00
entirely. The references can be anywhere in your document and the reference IDs
2015-11-02 05:38:55 +03:00
can be anything so long as they are unique.
2013-08-13 01:57:23 +04:00
2015-11-01 06:02:18 +03:00
There is also "implicit naming" which lets you use the link text as the id.
2013-08-13 01:57:23 +04:00
2016-01-08 09:35:16 +03:00
< pre > < code class = "highlight" > [ < span class = "nv" > This< / span > ][] is a link.
2022-01-16 06:43:14 +03:00
[ < span class = "nv" > This< / span > ]: < span class = "sx" > http://thisisalink.com/< / span > < / code > < / pre >
2016-01-08 09:35:16 +03:00
2015-11-01 06:02:18 +03:00
But it's not that commonly used.
2013-08-13 01:57:23 +04:00
2021-11-27 23:19:54 +03:00
### Table of contents
Some Markdown flavors even make use of the combination of lists, links and
headings in order to create tables of contents. In this case, heading titles in
lowercase are prepended with hash (`#`) and are used as link ids. Should the
heading have multiple words, they will be connected with a hyphen (`-`), that
also replaces some special characters. (Some other special characters are
omitted though.)
```md
- [Heading ](#heading )
- [Another heading ](#another-heading )
- [Chapter ](#chapter )
- [Subchapter <h3 /> ](#subchapter-h3- )
```
2022-12-10 18:05:34 +03:00
Nonetheless, this is a feature that might not be working in all Markdown
2021-11-27 23:19:54 +03:00
implementations the same way.
2015-11-01 06:02:18 +03:00
## Images
2021-11-27 23:19:54 +03:00
2015-11-01 06:02:18 +03:00
Images are done the same way as links but with an exclamation point in front!
2016-01-08 09:35:16 +03:00
2018-03-05 06:48:44 +03:00
```md
2014-09-10 20:07:19 +04:00
![This is the alt-attribute for my image ](http://imgur.com/myimage.jpg "An optional title" )
2015-11-01 06:02:18 +03:00
```
2016-01-08 09:35:16 +03:00
2015-11-01 06:02:18 +03:00
And reference style works as expected.
2013-08-13 01:57:23 +04:00
2016-01-08 09:35:16 +03:00
< pre > < code class = "highlight" > ![ < span class = "nv" > This is the alt-attribute.< / span > ][< span class = "ss" > myimage< / span > ]
2013-08-13 01:57:23 +04:00
2016-01-08 09:35:16 +03:00
[ < span class = "nv" > myimage< / span > ]: < span class = "sx" > relative/urls/cool/image.jpg< / span > < span class = "nn" > "if you need a title, it's here"< / span > < / code > < / pre >
2021-11-27 23:19:54 +03:00
2015-11-01 06:02:18 +03:00
## Miscellany
2021-11-27 23:19:54 +03:00
2015-11-01 06:02:18 +03:00
### Auto-links
2016-01-08 09:35:16 +03:00
2018-03-05 06:48:44 +03:00
```md
2014-05-12 04:14:07 +04:00
< http: / / testwebsite . com / > is equivalent to
[http://testwebsite.com/ ](http://testwebsite.com/ )
2015-11-01 06:02:18 +03:00
```
2013-08-13 01:57:23 +04:00
2015-11-01 06:02:18 +03:00
### Auto-links for emails
2016-01-08 09:35:16 +03:00
2018-03-05 06:48:44 +03:00
```md
2013-08-13 01:57:23 +04:00
< foo @ bar . com >
2015-11-01 06:02:18 +03:00
```
2013-08-13 01:57:23 +04:00
2015-11-01 06:02:18 +03:00
### Escaping characters
2016-01-08 09:35:16 +03:00
2018-03-05 06:48:44 +03:00
```md
2014-05-12 04:14:07 +04:00
I want to type *this text surrounded by asterisks* but I don't want it to be
in italics, so I do this: \*this text surrounded by asterisks\*.
2015-11-01 06:02:18 +03:00
```
2013-08-13 01:57:23 +04:00
2015-11-01 06:02:18 +03:00
### Keyboard keys
2015-10-01 07:42:19 +03:00
2021-11-27 23:19:54 +03:00
In GitHub Flavored Markdown, you can use a `<kbd>` tag to represent keyboard
2016-03-18 10:01:55 +03:00
keys.
2016-01-08 09:35:16 +03:00
2018-03-05 06:48:44 +03:00
```md
2015-10-01 07:42:19 +03:00
Your computer crashed? Try sending a
< kbd > Ctrl< / kbd > +< kbd > Alt< / kbd > +< kbd > Del< / kbd >
2015-11-01 06:02:18 +03:00
```
2021-11-27 23:19:54 +03:00
2015-11-01 06:02:18 +03:00
### Tables
2015-10-01 07:42:19 +03:00
2016-02-24 03:12:44 +03:00
Tables are only available in GitHub Flavored Markdown and are slightly
2015-11-01 06:02:18 +03:00
cumbersome, but if you really want it:
2016-01-08 09:35:16 +03:00
2018-03-05 06:48:44 +03:00
```md
2013-08-13 01:57:23 +04:00
| Col1 | Col2 | Col3 |
| :----------- | :------: | ------------: |
| Left-aligned | Centered | Right-aligned |
| blah | blah | blah |
2015-11-01 06:02:18 +03:00
```
2021-11-27 23:19:54 +03:00
2015-11-01 06:02:18 +03:00
or, for the same results
2013-08-13 01:57:23 +04:00
2018-03-05 06:48:44 +03:00
```md
2013-08-13 01:57:23 +04:00
Col 1 | Col2 | Col3
:-- | :-: | --:
Ugh this is so ugly | make it | stop
```
2016-01-08 09:35:16 +03:00
2021-11-27 23:19:54 +03:00
## Markdownlint
In order to simplify work with Markdown and to unify its coding style,
2022-11-11 12:38:32 +03:00
`Markdownlint` has been created. Available as a
[separate tool ](https://github.com/markdownlint/markdownlint )
as well as a plugin for some IDEs, it can be used to ensure validity and
readability of Markdown.
2021-11-27 23:19:54 +03:00
2015-11-01 06:02:18 +03:00
---
2021-11-27 23:19:54 +03:00
## Further reading
2013-08-13 01:57:23 +04:00
For more info, check out John Gruber's official post of syntax [here ](http://daringfireball.net/projects/markdown/syntax ) and Adam Pritchard's great cheatsheet [here ](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet ).
2021-11-27 23:19:54 +03:00
If you want to learn more on some major Markdown flavors' features, see:
- [GitHub flavored Markdown ](https://docs.github.com/en/github/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax )
- [GitLab flavored Markdown ](https://docs.gitlab.com/ee/user/markdown.html )