Skip to content

Try our new Crash Courses!

Buy one of our new Crash Courses, now hosted on Teachable.

Code blocks – Markdown

Demo

Summary

Markdown:

```
<!-- Code block example 1 -->
<p>This is HTML code.</p>
```

    // A sample code block
    console.log("Sample code block");

Output:

<!-- Code block example 1 -->
<p>This is HTML code.</p>

// A sample code block
console.log("Sample code block");

Details

There are two ways of creating a code block in Markdown. First, you can wrap your code snippet in 3 backticks at the top and bottom. Alternatively, you can indent your snippet by 4 spaces.

Click here to see an example of what this code looks like when rendered on GitHub. (Click the Raw button to see the actual Markdown code.)

Exercises

First, recreate the code snippet from the Demo section in your Markdown file. Then try customizing the text.

References

Markdown Reference on CommonMark

Lesson tags: Free Lesson
Back to: Markdown Reference > Markdown Syntax