How to Write Markdown

A beginner's guide to creating content using the Markdown language

April 2, 2024by Sunil Sandhu4 min read

Markdown is a simple markup language that allows you to format text using a few easy-to-remember syntax elements. It was created by John Gruber in 2004 as a way to write formatted text without using cumbersome HTML tags, and has since become a popular choice for formatting text on the web.

To use Markdown, you simply write your text in a plain-text editor using the Markdown syntax, and then convert it to HTML using a Markdown parser. This allows you to create rich, formatted text without having to write HTML directly.

Here are some basic examples of the Markdown syntax:

Headings

To create a heading in Markdown, you use the # character followed by a space and the heading text. The number of # characters you use indicates the level of the heading, with one # being the highest level (i.e. the title of your document) and six # characters being the lowest level (i.e. a subheading).

For example, to create a top-level heading, you would write:

# This is a top-level heading

To create a second-level heading, you would write:

## This is a second-level heading

And to create a third-level heading, you would write:

### This is a third-level heading

Emphasis

To create emphasis in Markdown, you use the * character (an asterisk) to indicate italics, or the ** characters (two asterisks) to indicate bold.

For example, to create italicized text, you would write:

*This text is italicized*

To create bold text, you would write:

**This text is bold**

Lists

To create a list in Markdown, you use the - character (a dash) to indicate each item in the list.

For example, to create a bulleted list, you would write:

- Item 1
- Item 2
- Item 3

To create a numbered list, you use the 1. syntax before each item in the list.

For example:

1. Item 1
2. Item 2
3. Item 3

Links

To create a link in Markdown, you use the [ and ] characters (square brackets) to enclose the link text, and the ( and ) characters (round brackets) to enclose the link URL.

For example, to create a link to the Google homepage, you would write:

[Google](https://google.com)

Images

To include an image in Markdown, you use the ![ and ] characters (an exclamation mark followed by square brackets) to enclose the alt text for the image, and the ( and ) characters to enclose the URL of the image.

For example, to include the image https://example.com/image.jpg with the alt text "A beautiful sunset," you would write:

![A beautiful sunset](https://example.com/image.jpg)

Code

To include code in Markdown, you use the backtick character (`) to enclose the code snippet. This will create a monospaced font and preserve any indentation in the code.

For example, to include the following code snippet:

function add(x, y) { return x + y; }

You would write:

`function add(x, y) {
  return x + y;
}`

Alternatively, you can use three backticks (```) to create a code block. This will display the code on its own line, with a grey background, and preserve any indentation and line breaks in the code.

HTML

You can also style your content using regular HTML elements. For example, if you want to write a piece of text in bold, you could write <p><strong>like this</strong></p> and the content will appear in bold.

Here's another example with more HTML used:

<h1>This is a top-level heading</h1>

<p><strong>This text is bold</strong></p>

<pre><code>function add(x, y) {
  return x + y;
}
</code></pre>

Conclusion

These are just a few examples of the Markdown syntax. There are many other elements you can use to format your text, including blockquotes, horizontal lines, tables, and more.

As you can see, Markdown is a simple and powerful way to format your text for the web. With just a few syntax elements, you can create rich, formatted text that is easy to read and write.

Whether you're writing a blog post on Differ, a README file, or any other type of document, Markdown is worth considering as a way to format your text.

Author
Author Avatar

Sunil Sandhu

Topics
programming
Related