Markdown Code Blocks
Code blocks can be used to display multiple lines of code. They preserve formatting and provide syntax highlighting when possible.
Basic Usage
To create a basic code block, wrap the code with three backticks (```):
```This is a code block.```
The result will look like this:
This is a code block.
An alternative way to create a code block is by adding four spaces before each line of code:
[space][space][space][space]This is a line of code.
[space][space][space][space]This is a line of code.
The result will look like this:
This is a line of code.
This is a line of code.
However, the recommended way to create a code block in GitHub Markdown is using triple backticks (```).
Syntax Highlighting
Optionally, a language can be specified for a code block to enable syntax highlighting. This can be done by appending the language to the starting backticks. The indent lines method (four spaces) does not support syntax highlighting, so using the former method is preferred:
```jsconsole.log('Hello world');```
The result will look like this:
console.log('Hello world');
All contributors
- Anonymous contributor
- Anonymous contributor
- Anonymous contributor
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Markdown on Codecademy
- Front-end engineers work closely with designers to make websites beautiful, functional, and fast.
- Includes 34 Courses
- With Professional Certification
- Beginner Friendly.115 hours
- Start at the beginning by learning HTML basics — an important foundation for building and editing web pages.
- Beginner Friendly.7 hours