Skip to content
Back to Journal
GuideMay 3, 2026·2 min read

How to Add a Code Block in Markdown

Fenced code blocks with syntax highlighting, inline code, and language identifiers. Complete guide.

The quick answer: Wrap code in triple backticks on their own lines. Add a language name after the opening backticks for syntax highlighting.

Fenced Code Block

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

The language identifier (python, javascript, bash, etc.) enables syntax highlighting. Supported languages include: python, js, ts, jsx, tsx, html, css, json, yaml, bash, sql, go, rust, and dozens more.

Inline Code

For short code references within a sentence, use single backticks: Use the print() function to display output.

Use inline code for variable names, function names, file paths, and short commands.

Common Language Identifiers

  • js or javascript — JavaScript
  • ts or typescript — TypeScript
  • py or python — Python
  • bash or sh — Shell/Terminal
  • json — JSON
  • html — HTML
  • css — CSS
  • sql — SQL
For the complete list of supported languages and syntax options, see the Markdown code reference.

Syntax Highlighting on Different Platforms

GitHub, GitLab, and MarkdownTools all support syntax highlighting with language identifiers. Discord renders code blocks but without highlighting — just monospace font.

Backtick Inside Inline Code

To show a backtick inside inline code, use double backticks as the delimiter: backtick `

Indented Code Block (Legacy)

You can also create code blocks by indenting every line with 4 spaces. This is the old syntax — fenced backticks are preferred as they support language identifiers.


Full reference: Markdown Code Blocks.

Ready to put this into practice? Paste your markdown into the free MarkdownTools PDF exporter or HTML converter — no signup required.

Frequently Asked Questions

How do you make a code block in markdown?

Wrap code in triple backticks on their own lines. Add a language name after the opening backticks (e.g. ```python) to enable syntax highlighting.

What is the difference between inline code and a code block?

Inline code uses single backticks and flows within a sentence. A code block uses triple backticks, starts on its own line, supports multiple lines, and optionally has syntax highlighting.

How do you add syntax highlighting to a code block?

Add the language identifier after the opening triple backticks: ```javascript, ```python, ```bash, etc. GitHub, GitLab, and MarkdownTools all support this.

MT

MarkdownTools Team

May 3, 2026

Try it free

Make your AI output beautiful

Paste markdown from ChatGPT or Claude. Pick a theme. Export as PDF or HTML in seconds.

Open App — It's Free