Discord Code Block: 7 Easy Ways to Use It (Examples)
A Discord code block lets you post text exactly as you typed it, in a monospace font, with no bold, italics or emoji conversion getting in the way. It is the easiest way to share code, commands, logs and ASCII art without breaking the formatting. This guide shows you how to make a Discord code block on desktop and mobile, how to turn on syntax highlighting, and how to fix the usual problems.
Short version: put one backtick (`) on each side of a word for an inline code block, or put three backticks (“`) on their own line above and below your text for a multi-line one. The rest of this page covers the details with copy-ready examples.
What Is a Discord Code Block?
A code block is a piece of a message that Discord shows in a grey box with a monospace font. Anything inside it is treated as plain text, so Discord ignores other Discord markdown such as bold or italics. That is why people use it for code, but also for tables, ASCII art, logs and anything that needs to stay aligned.
There are two kinds of Discord code block: inline (one line, inside a sentence) and multi-line (a full box, optionally with colours).
How to Make an Inline Discord Code Block
An inline code block is perfect for a command or a single value inside a normal sentence. Wrap the text in single backticks:
`npm install discord.js`
Discord shows npm install discord.js in a small grey highlight. Do not leave spaces between the backtick and the text, or the formatting may not apply.
How to Make a Multi-Line Discord Code Block
For more than one line, use three backticks. Put them on a line of their own, add your text, then close with three more backticks:
```
line one
line two
line three
```
On desktop, press Shift + Enter to start a new line without sending the message. Then press Enter once the closing backticks are in place.
Where is the backtick key?
- Windows and Mac (US keyboard): the key to the left of 1, under Esc.
- Other layouts: often Alt Gr plus a key near Enter, or a dedicated key beside the left Shift.
- iPhone and Android: open the symbols keyboard. On Android it sits on the second symbols page, on iPhone you can long-press the apostrophe key.
- Cannot find it? Copy the backtick from this page: ` and paste it.
How to Add Syntax Highlighting to a Discord Code Block
Type a language name straight after the opening three backticks, with no space. Discord uses the highlight.js library, so many languages work.
```js
const greeting = "Hello, Discord!";
console.log(greeting);
```
Common language tags you can use:
jsorjavascriptpyorpythonhtml,css,json,sqljava,cpp,cs,php,bashdiff,ini,yaml,md
If the language name is not recognised, Discord still shows the box, just without colours.
Discord Code Block Colours Without Code
You do not have to be posting real code to get coloured text. A few language tags are popular for simple highlights:
Green and red lines with diff
```diff
+ This line is green
- This line is red
```
Blue headings with ini
```ini
[This text is blue]
normal text
```
Full colours with ansi
The ansi tag uses escape codes to give you red, green, yellow, blue, pink, cyan and white text, plus bold and underline. It works in the desktop and web apps. We wrote a separate walkthrough: how to do colored text in Discord, and you can skip the typing with our Discord colored text generator.
Discord Code Block Limits You Should Know
- Message length: 2,000 characters for free users and 4,000 with Nitro. A long Discord code block counts every backtick and hidden character.
- No formatting inside: bold, italics and spoilers will not render inside a code block, they show as raw symbols.
- Mobile: syntax colours show on mobile, but ansi colours may not display in every app version.
- Backticks inside a block: typing three backticks inside a block will close it early. Add a zero-width space between them or split the message.
Discord Code Block Not Working? Quick Fixes
- Everything shows as plain text: check you used backticks (`), not apostrophes (‘) or quotes.
- Box stops halfway: you probably have a stray set of backticks inside the text.
- No colours: remove the space after the opening backticks, and check the language tag spelling.
- Wrong line breaks: use Shift + Enter, not Enter, between lines on desktop.
- Message will not send: you are over the character limit.
Still stuck? Discord explains the basics in its own Markdown Text 101 guide.
Make Your Discord Messages Stand Out
A Discord code block is only one tool. For tiny text read how to make small text in Discord, and for the full list of bold, italic, strikethrough and header syntax see our Discord markdown cheat sheet.
Discord Code Block FAQ
How do you make a code block in Discord?
Type three backticks, press Shift + Enter, write your text, press Shift + Enter again and type three more backticks. For a single line, wrap the text in one backtick on each side.
How do you add colour to a Discord code block?
Add a language tag after the opening backticks. Use diff for green and red lines, ini for blue text, or ansi for a full range of colours.
What is the backtick on a keyboard?
It is the key left of the number 1 on a US keyboard. On phones, open the symbols keyboard.
Why is my Discord code block not working?
Most often you typed an apostrophe instead of a backtick, left a space after the opening backticks, or put extra backticks inside the text.
What is the character limit for a Discord code block?
A code block shares the normal message limit: 2,000 characters, or 4,000 with Nitro.