Discord Code Blocks: The Complete Guide
Inline code, multi-line blocks, syntax highlighting with every supported language, diff and ANSI color tricks, and fixes for the mistakes that break formatting
To make a code block in Discord, put three backticks ``` on the line before and after your code. For short snippets inside a sentence, wrap the text in a single backtick instead. Add a language name right after the opening backticks — like ```python or ```js — to turn on syntax highlighting.
Part of our Discord series. This page covers code blocks in depth — for every other style, see the full guide.
Full Discord Markdown guide →Inline Code (Single Backticks)
Inline code is for short snippets that live inside a sentence: commands, file names, variable names, or key presses. Wrap the text in a single backtick on each side and Discord renders it in a monospace font on a dark chip, without breaking the flow of your message.
Inline code
One backtick on each side of the snippet.
Run `npm install` before starting
npm install before startingCommand in a sentence
Ideal for slash commands, so readers see exactly what to type.
Use the `/mute` command to silence the channel
File names and paths
Backticks also stop Discord from italicizing file_names_with_underscores.
Edit `config/settings.json` and restart the bot
Multi-Line Code Blocks (Triple Backticks)
For anything longer than a single line — code, logs, terminal output, config files — use a fenced block: three backticks on the line before and three on the line after. Everything inside keeps its exact spacing and line breaks, and other Markdown is not processed. Press Shift + Enter to add new lines without sending the message.
Plain multi-line block
No language identifier — best for logs and plain terminal output.
``` ERROR 2026-07-07 14:32:01 at handler (bot.js:42) at process (queue.js:17) ```
Preserve alignment
The monospace font keeps columns aligned — this is also the standard workaround for tables, which Discord does not support.
``` Name Role Status Alice Admin Online Bob Mod Away ```
Code blocks count toward the 2000-character message limit (4000 with Nitro). For longer code, upload a .txt or source file instead — Discord previews text files with highlighting.
Syntax Highlighting
Type a language identifier immediately after the opening three backticks — no space in between — and Discord colors the code using highlight.js. The identifier itself is not shown in the rendered message.
JavaScript
js and javascript both work.
```js const status = "deployed"; console.log(status); ```
Python
py is a valid shorthand too.
```python
def greet(name):
return f"Hello, {name}!"
```JSON config
Great for sharing bot configuration snippets.
```json
{
"prefix": "!",
"cooldown": 5
}
```If Discord does not recognize the identifier, the block still renders — just without colors. Highlighting shows on desktop, web, and mobile.
Supported Language Identifiers
Discord bundles the common highlight.js languages. These identifiers (and their aliases) all work after the opening backticks:
python / pyjavascript / jstypescript / tsjavaccpp / c++cs / csharpcsshtml / xmljsonyaml / ymlsqlbash / shphpruby / rbgorust / rskotlinswiftluadiffmarkdown / mdinipowershelldockerfileansiOther highlight.js languages such as scss, graphql, toml, and objectivec generally work too. Unknown identifiers are ignored gracefully. Need a code block for a README instead? Try the Markdown code block generator.
Diff Blocks (Red & Green Lines)
The diff language colors whole lines: lines starting with + render green and lines starting with - render red. It is the easiest way to color-code text in Discord and, unlike ANSI blocks, it works on mobile.
Changelog
Perfect for release notes and update announcements.
```diff + Added slash command support + New moderation dashboard - Removed legacy webhook ```
Pros and cons list
A popular non-code use: green for pros, red for cons.
```diff + Free and fast + Works on mobile - Only colors full lines ```
ANSI Blocks (Full Colored Text)
For colors beyond red and green, use an ansi code block with ANSI escape sequences like [31m (red), [32m (green), [34m (blue), and [0m (reset). The escape character (ESC, U+001B) is invisible — the copy buttons below include it so the examples paste straight into Discord. ANSI colors render on desktop and web only, not on mobile — mobile users see plain monospace text.
Red error line
```ansi ESC[31mBuild failed: missing tokenESC[0m ```
Bold green success line
```ansi ESC[1;32mAll tests passedESC[0m ```
The full color-code table (8 text colors, 8 backgrounds, bold and underline modifiers) is in the colored text section of the Discord Markdown guide.
Common Mistakes (and Fixes)
Space after the backticks
``` python (with a space) does not trigger highlighting — Discord treats python as the first line of code. The identifier must touch the backticks: ```python.
Apostrophes instead of backticks
The backtick ` (grave accent) is not the apostrophe ' or the quotation mark. On a US keyboard it shares a key with ~ in the top-left corner, below Esc.
Can't find the backtick on mobile
On iOS and most Android keyboards, switch to the symbols layout and long-press the apostrophe key — the backtick appears in the popup. On some Android keyboards it lives on the second symbols page (the =\< key).
Sending before the block is closed
Enter sends the message in Discord. Use Shift + Enter for new lines while typing a block, and make sure the closing ``` is in place before you hit Enter. Already sent it broken? Press the up arrow to edit your last message.
How to Escape Backticks
Sometimes you need to show a backtick literally — for example, when explaining code block syntax to someone else.
Backslash escape
A backslash before each backtick displays it as a normal character.
\`not code\`
Backtick inside inline code
Wrap the snippet in double backticks to show single backticks inside inline code.
``use `backticks` here``
Show triple backticks
Escape each backtick of the fence to display code block syntax without triggering it.
\`\`\`js code here \`\`\`
More escaping rules for asterisks, underscores, and other markers are in the escaping section of the main guide.
Code Blocks in Embeds & Bot Messages
Bots and webhooks can send rich embeds, and Discord renders Markdown — including code blocks — inside them:
- Description and field values render inline code and triple-backtick blocks, including language highlighting.
- Embed titles and field names do not render code blocks — keep those plain.
- Length limits apply: 4096 characters for the description, 1024 per field value — long code will be truncated.
Embed description with a code block (discord.js)
Escape the newlines (\\n) inside the string when building the embed programmatically.
```js
const embed = new EmbedBuilder()
.setTitle("Error report")
.setDescription("```js\nTypeError: x is undefined\n```");
```Writing bot replies from standard Markdown (or an AI answer)? The Markdown to Discord converter normalizes tables and headings into Discord-safe output.
Quick Tips
Markdown is off inside blocks
Bold, italics, mentions, and emoji shortcodes are not processed inside code blocks — what you type is exactly what renders.
Upload long code as a file
Past ~2000 characters, attach a .txt or source file instead — Discord shows an expandable preview and readers can download it.
Quote code cleanly
Inline code works inside quotes: > Use `/deploy preview` before merging.
Pick diff over ANSI for mobile
If your audience reads on phones, diff blocks color lines everywhere; ANSI colors are desktop/web only.
Frequently Asked Questions
How do I make a code block in Discord?
Type three backticks (```), press Shift + Enter, paste your code, press Shift + Enter again, and close with three more backticks. For a short snippet inside a sentence, wrap it in a single backtick instead: `like this`.
How do I get syntax highlighting in a Discord code block?
Type the language identifier immediately after the opening three backticks with no space — for example ```python or ```js — then put your code on the next lines and close with three backticks. Discord uses highlight.js, so most common language names and their short aliases work.
What languages does Discord syntax highlighting support?
Discord supports the languages bundled with highlight.js, including python, javascript (js), typescript (ts), java, c, cpp, csharp (cs), css, html/xml, json, yaml, sql, bash (sh), php, ruby, go, rust, kotlin, swift, lua, ini, powershell, dockerfile, markdown, diff, and ansi.
Why is my Discord code block not working?
The two most common causes are a space between the backticks and the language name (```python works, ``` python does not highlight) and using the wrong character — it must be the backtick ` (grave accent), not an apostrophe. Also make sure the closing three backticks are on their own line.
Where is the backtick key on a mobile keyboard?
On most iOS and Android keyboards, switch to the numbers/symbols layout, then long-press the apostrophe (’) key — the backtick ` appears in the popup. On Android you may find it on the second symbols page (=\<) instead.
How do I show a backtick inside a Discord code block?
For inline code, wrap the snippet in double backticks: ``use `backticks` here``. Inside a triple-backtick block, single backticks display fine as-is. To show a literal triple-backtick sequence, escape each one with a backslash: \`\`\`.
How do I make colored text in a Discord code block?
Use an ANSI code block: start with ```ansi, wrap your text in escape sequences such as ESC[31m for red or ESC[32m for green, reset with ESC[0m, and close the block. Colors render on Discord desktop and web but not on mobile.
How do I make red and green lines in Discord?
Use a diff code block: start with ```diff, then begin lines with + for green or - for red. It is the quickest cross-platform way to color-code lines, and unlike ANSI blocks it renders on mobile too.
Do Discord code blocks work inside embeds?
Yes. Bot and webhook embeds render Markdown in the description and field values, so triple-backtick code blocks with language identifiers work there too. Embed titles do not render code blocks, and field values are limited to 1024 characters.
Is there a character limit for Discord code blocks?
Code blocks count toward the normal message limit: 2000 characters for most users, 4000 with Nitro. If your code is longer, paste it in parts or upload it as a .txt or source file — Discord shows a preview with syntax highlighting for uploaded text files.