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 [31m for red or [34m for blue, then close with [0m 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.