MeshWorld India Logo MeshWorld.
Markdown Tutorial 3 min read

Code Blocks in Markdown - Syntax Highlighting Guide

Vishnu
By Vishnu
| Updated: May 8, 2026
Code Blocks in Markdown - Syntax Highlighting Guide

If you write technical content, you will display code regularly. Markdown gives you two ways to do it: inline code for short snippets and fenced code blocks for multi-line examples.


Inline Code

Inline code is used for short references within a sentence — variable names, file paths, commands, or any short piece of code.

Wrap the text in single backticks `.

Use the `print()` function to display output.

Run `npm install` to install dependencies.

The config file lives at `~/.bashrc`.

Use the print() function to display output.

Run npm install to install dependencies.

The config file lives at ~/.bashrc.

HTML equivalent: <code>print()</code>


Fenced Code Blocks

For multi-line code, use a fenced code block. Start and end with three backticks ``` on their own lines.

```
function greet(name) {
  return "Hello, " + name;
}
```
function greet(name) {
  return "Hello, " + name;
}

Syntax Highlighting

Add a language identifier after the opening backticks to enable syntax highlighting. Most Markdown renderers (GitHub, GitLab, Hugo, many static site generators) support this.

```javascript
function greet(name) {
  return `Hello, ${name}!`;
}
```
function greet(name) {
  return `Hello, ${name}!`;
}
```python
def greet(name):
    return f"Hello, {name}!"
```
def greet(name):
    return f"Hello, {name}!"
```bash
npm install
npm run dev
```
npm install
npm run dev

Common Language Identifiers

LanguageIdentifier
JavaScriptjavascript or js
TypeScripttypescript or ts
Pythonpython or py
Bash / Shellbash or sh
HTMLhtml
CSScss
SQLsql
JSONjson
YAMLyaml
Markdownmarkdown or md
Gogo
Rustrust

Indented Code Blocks (older syntax)

You can also create a code block by indenting lines with four spaces. This is the original Markdown syntax but fenced blocks are preferred — they’re easier to read and support syntax highlighting.

    This is an indented code block.
    Every line is indented with 4 spaces.
This is an indented code block.

Escaping Backticks Inside Code

If your code contains a backtick, use double backticks for the outer wrapper:

`` Use `backticks` like this ``

Use `backticks` like this


Best Practices

  • Always specify the language for code blocks — it makes content easier to read and helps syntax highlighters.
  • Use inline code for anything shorter than a line.
  • Don’t use code blocks just to indent text — use them only for actual code or terminal output.

Quick Reference

`inline code`

```language
multi-line
code block
```

Hope you find this helpful!

Keep smiling