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

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.

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