Markdown Syntax Cheat Sheet — Every Element with Examples

Markdown is the formatting language behind almost everything a developer writes: README files, GitHub issues, documentation sites, wikis, and chat messages. It is designed to be readable as plain text and to convert cleanly to HTML. This cheat sheet covers every core markdown element — headings, emphasis, lists, links, images, code, blockquotes, horizontal rules, and escaping — with the exact syntax you can copy and paste. Keep it bookmarked, or open our free markdown previewer in another tab and try each example live.

Headings

Headings start with hash characters. One hash is an H1, two hashes an H2, and so on down to six hashes for an H6. Always put a space between the hashes and the heading text — some renderers refuse to parse the heading without it.

# Heading 1
## Heading 2
### Heading 3
#### Heading 4
##### Heading 5
###### Heading 6

Heading 1 (alternate style)
===========================

Heading 2 (alternate style)
---------------------------

The alternate "setext" style with equals signs and dashes only supports two levels, so most teams standardise on the hash style. Use exactly one H1 per document and do not skip levels — an H2 should not jump straight to an H4.

Emphasis: Bold, Italic, and Combinations

Wrap text in one asterisk or underscore for italic, and two for bold. Three gives you bold italic. Asterisks are the safer choice because underscores can misbehave inside words like snake_case identifiers.

*italic*        or  _italic_
**bold**        or  __bold__
***bold italic***
**bold with *nested italic* inside**

Lists: Unordered, Ordered, and Nested

Unordered lists use a dash, plus, or asterisk followed by a space. Ordered lists use a number and a period — the actual numbers do not matter, because the renderer renumbers them automatically. Nest items by indenting two to four spaces.

- First item
- Second item
  - Nested item
  - Another nested item
- Third item

1. Step one
2. Step two
   1. Sub-step
3. Step three

1. You can also write every line as "1."
1. The renderer numbers them 1, 2, 3 anyway
1. Handy when you reorder steps often

The "all ones" trick in the last example is popular in documentation teams: inserting a new step in the middle never forces you to renumber the rest of the list.

Links and Images

A link is text in square brackets followed by a URL in parentheses. An image is the same thing with an exclamation mark in front — the bracket text becomes the alt text. You can also define reference-style links, which keep long URLs out of your paragraphs.

[Link text](https://example.com)
[Link with title](https://example.com "Shown on hover")

![Alt text for the image](https://example.com/diagram.png)

Reference style:
Read the [official docs][docs] and the [API guide][api].

[docs]: https://example.com/docs
[api]: https://example.com/api

Always write meaningful alt text for images — it is what screen readers announce and what appears if the image fails to load.

Code: Inline and Fenced Blocks

Wrap inline code in single backticks so commands and identifiers stand out from prose. For multi-line code, use a fenced block: three backticks on their own line before and after the code. Add a language name right after the opening fence to get syntax highlighting on GitHub and most documentation sites.

Run `npm install` before starting the dev server.

```js
function greet(name) {
  return `Hello, ${name}!`;
}
```

```python
def greet(name):
    return f"Hello, {name}!"
```

To show a backtick inside inline code, use double backticks:
`` code with a ` backtick ``

Blockquotes, Horizontal Rules, and Escaping

A blockquote line starts with a greater-than sign followed by a space. Quotes can be nested and can contain other markdown such as lists and bold text. A horizontal rule is three or more dashes, asterisks, or underscores on a line by themselves.

> This is a blockquote.
> It can span multiple lines.
>
> > And blockquotes can be nested.

---

Escaping special characters with a backslash:
\*not italic\*
\# not a heading
\[not a link\]
1\. not a list item

Escaping matters whenever your text happens to start with a markdown trigger character. A line that begins with an asterisk, hash, or a number and period will otherwise be interpreted as formatting. The backslash tells the renderer to treat the character as plain text.

  • Characters worth escaping: asterisk, underscore, hash, backtick, square brackets, and the pipe character inside tables
  • Line breaks: end a line with two spaces (or a backslash) to force a break without starting a new paragraph
  • Paragraphs: separate them with one blank line — a single newline is usually collapsed into the same paragraph

Frequently Asked Questions

What is markdown used for?

Markdown is a lightweight markup language used to format plain text. Developers use it for README files, documentation, GitHub issues and pull requests, blog posts, wikis, and chat messages. It converts to HTML for display.

How do I write a code block in markdown?

Wrap inline code in single backticks. For multi-line code blocks, use three backticks (a fenced code block) on the lines before and after the code, optionally followed by a language name like js or python for syntax highlighting.

Is there a free tool to preview markdown online?

Yes. Dev Brains AI offers a free markdown previewer. You type markdown on one side and see the rendered output live on the other — no signup required.

Try the Free Markdown Previewer

Paste any example from this cheat sheet and watch it render instantly with live side-by-side markdown editing in your browser. No signup, no cost.

Related articles