← Back to Blogs Tutorials 3 min read

How to Use Code Blocks in Discord: Single & Multi-Line Guide

How to Use Code Blocks in Discord: Single & Multi-Line Guide
Quick Syntax `inline` ``` multi-line ```

Use single backticks for inline code and triple backticks for multi-line code blocks.

Shortcut: Ctrl + Shift + M or + Shift + M

Code blocks are essential on Discord if you share commands, snippets, config files, or any text where formatting matters. Without code blocks, Discord tries to render your text as Markdown, which breaks things like asterisks, underscores, and special characters. Code blocks tell Discord to display everything exactly as typed.

This guide covers how to use code blocks on Discord for both single-line and multi-line snippets, plus syntax highlighting with language tags. For a complete reference of every formatting option, check out The Ultimate Discord Text Formatting Guide.


Single-Line Code Blocks on Discord

A single backtick on each side creates an inline code block. This is best for short commands, filenames, or single words you want to display literally.

Inline Code Syntax

`this is inline code`

Type a backtick (`), then your text, then another backtick. The text inside will appear in a monospace font with a dark background and will not trigger any Markdown formatting. For example, `**hello**` shows as **hello** with literal asterisks instead of bold text.

Where to Find the Backtick Key

On US keyboards, the backtick (`) shares a key with the tilde (~) next to the number 1 key. On UK keyboards, it is next to the Enter key. On mobile, backticks are usually on the symbols page alongside other punctuation.


Multi-Line Code Blocks on Discord

Triple backticks create a larger code block that preserves line breaks, indentation, and spacing. This is what you want for pasting config files, JSON, logs, or any multi-line content.

Basic Multi-Line Syntax

Open with three backticks on their own line, type or paste your content, then close with three backticks on their own line.

```
line one of your code
line two of your code
line three
```

Everything between the triple backticks is displayed exactly as typed. Line breaks, spaces, tabs, and special characters are all preserved.

Discord chat showing both inline code and a multi-line code block

Inline code and a multi-line code block Discord messages

Syntax Highlighting with Language Tags

You can add a language name right after the opening triple backticks to enable syntax highlighting. Discord highlights keywords, strings, and comments in the appropriate colors for that language.

```python
def hello():
    print("Hello, Discord!")
```

Supported languages include python, javascript, html, css, json, bash, yaml, sql, c, cpp, java, ruby, go, rust, and many more. If the language is not recognized, Discord displays the block as plain monospace text without highlighting.


Code Blocks on Discord Mobile

Typing backticks on mobile requires switching to the symbols keyboard, but the process is the same.

iOS (iPhone / iPad)

  1. 1

    Tap 123 then #+= to find the backtick key.

  2. 2

    For inline code: type `, your text, then `.

  3. 3

    For multi-line: type ```, press Return, paste your content, press Return, then type ```.

  4. 4

    Add a language tag after the opening ``` for syntax highlighting (e.g. ```python).

Android

  1. 1

    Tap ?123 then =\< to access the backtick key.

  2. 2

    Type ` for inline code around your text.

  3. 3

    For multi-line, open with ```, paste your code on new lines, close with ```.

  4. 4

    If your keyboard does not have a backtick key, copy ` from another message and paste it.

Tip Pro tip: On some mobile keyboards, you can long-press the tilde or apostrophe key to reveal the backtick as an alternate character.

When To Use Inline vs Multi-Line Code Blocks

  • Inline code (`text`): Use for short commands, filenames, variable names, single words, or inline references. It blends with surrounding text.
  • Multi-line code (```text```): Use for anything longer than one line, including scripts, config files, logs, error messages, and structured data like JSON or YAML.

A good rule of thumb: if it fits in one line and you want it to sit next to normal text, use inline. If it needs its own space with preserved formatting, use triple backticks.


Code Blocks Not Working on Discord? Try These Fixes

Common Issues

  • You are using the wrong quote character. Code blocks require backticks (`), not single quotes (') or apostrophes. The backtick key is different from the quote key on most keyboards.
  • Your triple backticks are not on their own lines. For multi-line blocks, the opening ``` must be on its own line before your content, and the closing ``` must be on its own line after. Putting them inline with text breaks the block.
  • You have extra spaces inside the backticks. ` text with spaces ` still works for inline code, but it looks messy. Keep the text flush against the backticks: `text`.
  • Syntax highlighting is not working. Make sure the language tag comes immediately after the opening ``` with no space. For example, ```python works, but ``` python with a space may not.
  • Your code block is breaking the chat layout. Extremely long lines without line breaks can create horizontal scroll. Manually wrap long lines at reasonable widths before pasting into a code block.

Code Blocks Discord FAQ

What is the difference between single and triple backticks on Discord?
Single backticks (`text`) create inline code that sits within a sentence. Triple backticks (```text```) create a separate block that preserves line breaks, indentation, and supports syntax highlighting.
How do I add syntax highlighting to a Discord code block?
Add the language name right after the opening triple backticks: ```python, ```javascript, ```json, etc. Discord highlights keywords based on the language. If it does not recognize the language, it shows plain monospace text.
Can I use code blocks on Discord mobile?
Yes. Tap 123 then #+= (iOS) or ?123 then =\< (Android) to find the backtick key. Type single backticks for inline code or triple backticks for multi-line blocks.
How do I type a backtick on a keyboard?
On US keyboards, the backtick (`) is next to the number 1 key. On UK keyboards, it is next to Enter. On mobile, it is on the symbols page. The backtick shares a key with the tilde (~) on most layouts.
Why is my code block showing formatting instead of raw text?
You probably used single quotes (') instead of backticks (`). Only backticks create code blocks. Single quotes are treated as regular text and do not prevent Markdown rendering.
Can I use bold or italic inside a code block?
No. Code blocks display everything literally. Any Markdown symbols inside backticks will show as plain text, not formatted. If you need bold inside code-like text, place the formatting outside the code block.