Skip to content

Instantly share code, notes, and snippets.

@Cube707
Last active April 19, 2024 23:15
Show Gist options
  • Star 14 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Cube707/810e9441de3aa2e2a2cc79eb4f0adaaf to your computer and use it in GitHub Desktop.
Save Cube707/810e9441de3aa2e2a2cc79eb4f0adaaf to your computer and use it in GitHub Desktop.
GiHub Markdown cheatsheet

A GitHub Markdown Cheatsheet

This show usable Markdown features on GitHub as a side by side comparison. This focuses on Markdown files, while most of also works in comments etc., there are some differences, so keep that in mind.

Table of Contents

Headings
Line Breaks
Inline text formatting
Links
Horizontal Rule
Code and Syntax Highlighting
Maths
Blockquotes
Lists
Definition lists
Tables
Images
Sources and more information

Headings

heading level 1

heading level 2

heading level 3

heading level 4

heading level 5
heading level 6
# heading level 1

## heading level 2

### heading level 3

#### heading level 4

##### heading level 5

###### heading level 6

Line Breaks

Here's a line for us to start with.

Leave a blank line to start a separate paragraph.

This line is also a separate paragraph, but... continuing on the next line puts it in the same paragraph.

You can also put manual line-breaks
with two spaces at the end of the line
or with HTML

Here's a line for us to start with.

Leave a blank line to start a *separate paragraph*.

This line is also a separate paragraph, but...
continuing on the next line puts it in the *same paragraph*.

You can also put manual line-breaks  
with two spaces at the end of the line  
or with HTML <br>

Inline text formatting

Emphasis, aka italics, (this also works)

Strong emphasis, aka bold, (or this)

Combined both in one context

Strikethrough uses two tildes

Inline code with single backticks.

Inline Math $a=1+2$ with LaTeX

HTML Options:

User input with <kbd>

Program output with <samp>

Mark variables with <var>

inserted Text with <ins>

deleted Text with <del>

Quote with <q> to get quotation marks

Subscriptsub with <sub> and Superscriptsup with <sup>

_Emphasis_, aka _italics_, (*this* also works)

**Strong emphasis**, aka **bold**, (or __this__)

**Combined _both_ in one context**

~~Strikethrough~~ uses two tildes

Inline code with `single backticks`.

Inline Math $a=1+2$ with LaTeX


_HTML Options:_

<kbd>User input</kbd> with `<kbd>`

<samp>Program output</samp> with `<samp>`

Mark <var>variables</var> with `<var>`

<ins>inserted</ins> Text with `<ins>`

<del>deleted Text</del> with `<del>`

<q>Quote</q> with `<q>` to get quotation marks

Subscript<sub>sub</sub> with `<sub>` and
Superscript<sup>sup</sup> with `<sup>`

Links

inline-style link

inline-style link with title

reference-style link

relative reference to a repository file

You can use numbers for reference-style link definitions

Or leave it empty and use the link text itself

URLs and URLs in angle brackets will automatically get turned into links. http://www.example.com or http://www.example.com and sometimes example.com (but not on Github, for example).

And HTML also works here: GitHub

Some text to show that the reference links can follow later.

[inline-style link](https://www.example.com)

[inline-style link with title](https://www.example.com "Hover Me")

[reference-style link][Arbitrary case-insensitive label]

[relative reference to a repository file](../blob/master/LICENSE)

[You can use numbers for reference-style link definitions][1]

Or leave it empty and use the [link text itself]

URLs and URLs in angle brackets will automatically get turned
into links. http://www.example.com or <http://www.example.com>
and sometimes example.com (but not on Github, for example).

And HTML also works here: <a href="https://github.com">GitHub</a>

Some text to show that the reference links can follow later.

[Arbitrary case-insensitive label]: https://www.mozilla.org
[1]: http://slashdot.org
[link text itself]: http://www.reddit.com

Horizontal Rule

Three or more...


Hyphens


Asterisks


Underscores

Three or more...

---

Hyphens

***

Asterisks

___

Underscores

Code and Syntax Highlighting

Code blocks are part of the Markdown spec, but syntax highlighting isn't. However, many renderers -- like GitHub's -- support any common programming language. Here you can find a list of supported languages.

We already know that inline code can be created with single backticks. Alternatively you can use the code HTML-tag.

Blocks of code are fenced by lines with three backticks ``` or the pre HTML-tag.

You select the language to be used for highlighting as shown here:

No language indicated, so no syntax highlighting.
But you could explicitly use `no-highlight`
var s = "JavaScript syntax highlighting";
alert(s);
# we can also use the HTML tag
import antigravity
print("hello world")
<title>HTML with syntax highlighting</title>
<p>
  But for HTML, we need to use ```
</p>
We already know that inline code can be created
with `single backticks`. Alternatively you can use
the <code>code</code> HTML-tag.

Blocks of code are fenced by lines with three
backticks <code>```</code> or the <code>pre</code>
HTML-tag.

You select the language to be used for highlighting
as shown here:
```
No language indicated, so no syntax highlighting.
But you could explicitly use `no-highlight`
```

```javascript
var s = "JavaScript syntax highlighting";
alert(s);
```
<pre lang="python">
# we can also use the HTML tag
import antigravity
print("hello world")
</pre>
```html
<title>HTML with syntax highlighting</title>

But for HTML, we need to use ```

```

Maths

You can use LaTex syntax to write Maths and equations

You can use it inline with a single $: $a=1+2$

Or you can create an equation block with $$

$$ f(x) = \sum^\infty_{i=0} \frac{i}{a} + b^2 $$

You can use it inline with a single `$`: $a=1+2$

Or you can create an equation block with `$$`

$$ f(x) = \sum^\infty_{i=0} \frac{i}{a} + b^2 $$

Blockquotes

Blockquotes are very handy in email to emulate reply text. This line is part of the same quote.

Or you can use HTML for this too

You can also use this nice trick (but only on GitHub):

image

> Blockquotes are very handy in email to emulate reply text.
> This line is part of the same quote.

<blockquote>
  Or you can use HTML for this too
</blockquote>

You can also use this nice trick (but only on GitHub):

> **Note**
> this is something you should note

> **Warning**
> last warning, your really shouldn't do this!

Lists

  1. First ordered list item
  2. Another item
    • Unordered sub-list
  3. The exact numbers doesn't matter, just that it's a number
    1. Ordered sub-list
  4. By the way, you can split you list items over multiple lines. Simply keep indenting.
  • Unordered list can use asterisks
  • Or minuses
  • Or pluses
1. First ordered list item

2. Another item

    * Unordered sub-list

1. The exact numbers doesn't matter, just that it's a number

    1. Ordered sub-list

4. By the way, you can split you list items
    over multiple lines.
    simply keep indenting.


* Unordered list can use asterisks
- Or minuses
+ Or pluses

Definition lists

This is a special type of list that originally comes from .rst documents. It's not part of Markdown, but you can use HTML to use them on GitHub.

Definition list are made up of three Tag:

<dl>
it wraps the whole list
<dt>
text or word to define
<dd>
this containes the actuall definition
Example
This is the text defining it
Definition list are made up of three Tag:

<dl>
  <dt><code><dl></code></dt>
  <dd>it wraps the whole list</dd>

  <dt><code><dt></code></dt>
  <dd>text or word to define</dd>

  <dt><code><dd></code></dt>
  <dd>this containes the actuall definition</dd>

  <dt>Example</dt>
  <dd>This is the text defining it</dd>
</dl>

Tables

Colons can be used to align columns.

Tables Are Cool
col 3 is right-aligned $1600
col 2 is centered $12
zebra stripes are neat $1

There must be at least 3 dashes separating each header cell. The outer pipes (|) are optional, and you don't need to make the raw Markdown line up prettily. You can also use inline Markdown.

Markdown Less Pretty
Still renders nicely
1 2 3
Colons can be used to align columns.

| Tables        | Are           | Cool  |
| ------------- |:-------------:| -----:|
| col 3 is      | right-aligned | $1600 |
| col 2 is      | centered      |   $12 |
| zebra stripes | are neat      |    $1 |

There must be at least 3 dashes separating each header cell.
The outer pipes (|) are optional, and you don't need to make
the raw Markdown line up prettily.
You can also use inline Markdown.

Markdown | Less | Pretty
--- | --- | ---
_Still_ | `renders` | **nicely**
1 | 2 | 3

Images

Images are links that are prefixed with a ! and use an image URL. By default, they use the images original size, but shrink it to fit the page. If you need more control over the size, use HTML.

Inline-style: alt text

Reference-style: alt text

Here HTML can actually benefit you, as it gives more control:

Text next to image

Images are links that are prefixed with a `!` and use an image URL.
By default, they use the images original size, but shrink it to fit
the page. If you need more control over the size, use HTML.

Inline-style:
![alt text](https://badges.aleen42.com/src/github.svg "Hover Me")

Reference-style:
![alt text][github-badge]

Here HTML can actually benefit you, as it gives more control:

<img
  src="https://badges.aleen42.com/src/github.svg"
  width="200px"
  align="right"
/>

Text next to image

<div align="center">
  <img
    src="https://badges.aleen42.com/src/github.svg"
    width="60px"
    height="60px"
  />
</div>

[github-badge]: https://badges.aleen42.com/src/github.svg "also hover"
[logo]: https://simpleicons.org/icons/markdown.svg "also hover"

Sources and more information

Markdown Cheatsheet by Adam Pritchard
HTML Tags You Can Use on GitHub by Sean Hammond
Guide to aligning images in github readme.md files by David Wells

@GrantBirki
Copy link

I had no idea you could do this...

Note
this is something you should note

Warning
last warning, your really shouldn't do this!

And I work at GitHub.. Absolutely amazing, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment