Discord Code Blocks

How to make a code block in Discord — with syntax highlighting, colors, a live preview and one-click copy

Quick answer: wrap your code in three backticks ``` on each side for a multi-line block, or a single backtick ` for inline code. Add a language right after the opening backticks — ```js — for colored syntax highlighting.

Discord Code Block Generator

Paste your code, pick a language for syntax highlighting, and copy the ready-to-paste Discord markup. A live Discord-style preview shows how it will look.

Every Discord Code Block Syntax

Click any code to copy it. All of these work in any Discord message — desktop, web, iOS, and Android.

What you get Markdown Notes
Inline code`inline code`Single backtick. Stays on the same line, grey monospace.
Single-line block```one line block```Three backticks, no language. A box on one line.
Multi-line block``` ⏎ code ⏎ ```Use Shift+Enter for the line breaks inside the block.
JavaScript highlight```js ⏎ … ⏎ ```Add a language after ``` for colored keywords.
Python highlight```python ⏎ … ⏎ ```Works with js, py, json, html, css, sql, cpp, java…
Green & red (diff)```diff ⏎ + … ⏎ - … ⏎ ```Lines starting with + are green, - are red.
Golden text (fix)```fix ⏎ … ⏎ ```The whole block renders in a warm gold colour.
Custom colors (ansi)```ansi ⏎ [2;31m… ⏎ ```ANSI escape codes let you pick any colour.

Tip: ⏎ means a line break — press Shift+Enter inside Discord to add it without sending the message. Click a table cell to copy the real markup (line breaks included).

Discord Code Block Colors (Syntax Highlighting Cheatsheet)

Discord runs code blocks through highlight.js, so each language tag paints text a different colour. These are the most popular tricks people use to get colored text inside Discord. Click a card to copy the block.

diff — green & red

Click to copy
+ this line is green
- this line is red

The number-one trick for colored text. Start a line with + for green or - for red.

fix — golden text

Click to copy
this whole block is gold

Every line in a fix block turns warm gold — great for warnings.

ansi — any color

Click to copy
Red Blue Green

Use escape codes like [2;31m (red) to colour individual words, then reset with [0m.

css — orange values

Click to copy
.aesthetic { color: pink; }

A css block tints selectors, properties and values in different hues.

json — keys & values

Click to copy
{ "status": "ok", "count": 7 }

Clean colouring for config and API responses — strings, numbers and keys all differ.

bash — comments & strings

Click to copy
# a comment
echo "hello"

A bash block greys out # comments and colours quoted strings.

How to Make a Code Block in Discord (Step by Step)

Discord borrows its formatting from Markdown, and code blocks are one of its most useful features. They give your text a fixed-width monospace font on a dark background, which is perfect for sharing snippets, commands, logs, API responses, or anything where spacing and characters need to stay exactly as you typed them. The character that does all the work is the backtick (`) — not the apostrophe — which lives in the top-left corner of most keyboards.

For a short snippet that stays in the flow of a sentence, use inline code: one backtick before and after, like `npm install`. For anything longer, use a code block: three backticks to open, then your code, then three backticks to close. The trick most people miss is the line breaks — inside the Discord message box you add them with Shift+Enter so you don't send the message early. Put the opening ``` on its own line, paste your code beneath it, and close with ``` on a final line.

Once you can make a plain block, the next step is syntax highlighting. Type a language name immediately after the opening backticks, with no space — ```js, ```python, ```json, and so on. Discord recognises dozens of languages through the highlight.js library and automatically tints keywords, strings, numbers and comments. The language tag only affects colour; it never changes your text.

How to Get Colored Text in Discord Code Blocks

Discord doesn't offer a colour picker, so people borrow the syntax highlighter to fake coloured text. The most famous method is the diff block: open with ```diff, then start a line with a + to make it green or a - to make it red. It's the quickest way to post a green "success" or a red "error" line. The fix block (```fix) turns an entire block gold, which is handy for highlighting warnings or pinned notes.

For full control, the ansi block (```ansi) supports real ANSI escape codes. Wrap a word in a colour code such as  for red or  for blue, then close with  to reset. Unlike the diff and fix hacks, ansi lets you colour individual words rather than whole lines, and it renders on both the desktop client and the modern mobile apps. If you only need colour in a username or channel name — where no Markdown works at all — you'll instead want Unicode styled letters from a font generator.

Inline Code vs Code Blocks: When to Use Each

Reach for inline code when you're naming a single command, file, variable, or value mid-sentence — it keeps your message compact and readable. Reach for a code block when the content has multiple lines, needs to preserve indentation, or benefits from syntax colours. A common mistake is pasting a long script as inline code; it wraps awkwardly and loses its line breaks. Another is mixing them up on mobile, where autocorrect sometimes swaps the straight backtick for a curly quote and silently breaks the formatting.

Code blocks are also "format-proof": any asterisks, underscores or other Markdown inside a block are shown literally instead of being turned into bold or italics. That makes them the safest container when you need Discord to display characters exactly as typed. If your block refuses to render, check three things — that you used real backticks, that there's no space between the backticks and the language name, and that the opening and closing fences each have exactly three backticks.

Frequently Asked Questions

How do you make a code block in Discord?

Wrap your code in three backticks (```) on each side. For a multi-line block, put the opening ``` on its own line, your code on the lines below, and the closing ``` on a final line. For a short snippet on the same line, use a single backtick on each side: `code`.

How do I add syntax highlighting to a Discord code block?

Type a language name directly after the opening three backticks with no space, for example ```js, ```python, ```css or ```json. Discord uses highlight.js to colour keywords, strings, numbers and comments for that language.

How do I make colored text in a Discord code block?

Use a language whose highlighting produces colour. The ```diff block turns lines starting with + green and lines starting with - red. The ```fix block shows golden text, and ```ansi lets you set any colour with escape codes such as  for red.

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

Inline code uses a single backtick on each side and keeps the snippet on the same line as your sentence, with no syntax highlighting. A code block uses three backticks, spans multiple lines in its own dark box, and supports language syntax highlighting.

How do I type three backticks on mobile?

The backtick key is on the symbols/numbers layer of the iOS and Android keyboards — switch to it and the backtick (`) is usually near the top-left next to the numbers. Tap it three times, add a line break, type your code, then add three more backticks. Or just copy a ready-made block from the generator above.

Why is my Discord code block not working?

The most common causes are using regular quotes or apostrophes instead of the backtick character (`), leaving a space between the backticks and the language name, or not closing the block with a matching set of three backticks. Code blocks also do not render in usernames, channel names or server names — only inside messages.

Can I highlight a whole word in color inside a code block?

Yes. With the ```ansi block you wrap the word in an escape code, for example  for green, then reset with . ANSI colour blocks render on desktop and the modern mobile apps, which makes them the most reliable way to colour specific words.

Explore More Tools

Copied!