How to Make a Code Block in Discord
Wrap short code in one backtick: `code`. For several lines, put three backticks on the line above and the line below.
Inline code
One backtick on each side gives a small grey box inside your sentence, like `npm install`. It is great for commands, file names and settings.
Multi-line code block
- Type three backticks
```and press Shift + Enter for a new line. - Paste or type your code.
- On a new line, type three more backticks and send.
How do you add syntax highlighting?
Write the language name right after the first three backticks, with no space. For example ```js, ```python, ```css or ```json. Discord colors the code for that language. A few fun ones exist too. ```diff turns lines starting with + green and lines starting with - red.
Where is the backtick key?
On a US keyboard it is left of the 1 key, under Esc. On iPhone, press and hold the apostrophe key on the 123 page. On Gboard, it is on the =\< page.
Code block looks broken?
- You used apostrophes
'instead of backticks. The backtick key sits under Esc on most keyboards. - The closing backticks are missing, so the rest of the message turns into code.
- There is a space between the backticks and the language name.
- On a phone, long-press the apostrophe key to find the backtick.
What people use code blocks for
Discord does not format anything inside them. Stars, underscores and links stay as typed. That makes code blocks the safe way to share code, logs or ASCII art. Code blocks are also the base for Discord colored text, which uses the ansi language.
Frequently asked questions
Which languages get colors?
Most common ones: js, py, css, html, json, diff, bash, cs, cpp and more. If a name does not work, the block still shows, just without colors.
How do I get syntax highlighting in Discord?
Write the language name right after the first three backticks, like ```js or ```py, then start your code on the next line.
Do code blocks work on mobile?
Yes, they show fine. Syntax colors can look weaker on mobile, but the block itself works.