Discord Code Block Guide
How to use code blocks in Discord messages. Format code with syntax highlighting, inline code and multiline blocks.
Use `backticks` for inline codeWrap text in single backticks for inline monospace. Example: The command is `!ban`
```
const greeting = "hello";
console.log(greeting);
```Wrap in triple backticks for multiline blocks.
```javascript
const greeting = "hello";
console.log(greeting);
```Add a language tag after the first triple backtick: js, py, html, css, json, diff.
Supported languages
FAQ
How do I type backticks?
The backtick key is ` to the left of 1 on most keyboards.
Do code blocks work on mobile?
Yes, but typing backticks on mobile can be awkward. Copy paste is easier.
Inline code versus code blocks
Discord offers two distinct code formats and they serve different purposes. Inline code, written with single backticks around a short fragment, renders in a monospace font with a subtle background and stays on the same line as surrounding text. It is the right choice for a variable name, a file path, a command or a short value mentioned mid-sentence.
Code blocks, written with triple backticks, create a separate boxed region that preserves line breaks and indentation exactly. They are the right choice for anything longer than a fragment, and the only option that keeps multi-line formatting intact.
Both formats share one important property: markdown parsing is disabled inside them. Asterisks, underscores and tildes display literally rather than triggering bold, italic or strikethrough. This makes code formatting the simplest way to post text containing markdown characters without escaping every one individually.
Syntax highlighting and language names
Adding a language name immediately after the opening triple backticks enables syntax highlighting. The language must be followed by a line break, with the code beginning on the next line - this is the detail people most often get wrong.
Discord's highlighter is built on a widely used library, so it recognises a large set of languages: js, ts, python, java, cpp, cs, go, rust, ruby, php, sql, html, css, json, yaml, xml, bash and many more. Common aliases generally work, so both js and javascript are accepted.
If a language is unrecognised, Discord silently renders the block without highlighting rather than showing an error. When highlighting does not appear, the cause is almost always a misspelled language name or a missing line break after it.
Two special cases are worth knowing. The diff language colours lines beginning with a plus sign green and a minus sign red, which is useful for showing changes or for simple green/red status lists. The ansi language enables manual colour control through escape codes, and is the only way to produce arbitrary coloured text in Discord.
Posting code that contains backticks
A snippet containing triple backticks - documentation about markdown, for instance - terminates the surrounding block early and breaks the rest of the message. The fix is to escape the inner backticks with a backslash before each one, which displays them literally without closing the block.
For inline code that itself needs to contain a backtick, the cleaner solution is to wrap the fragment in double backticks instead of single ones. The parser matches the outermost pair, so a single backtick inside is treated as content.
Bots relaying user-supplied text into code blocks should escape backticks defensively before sending. Otherwise a user can break the bot's message formatting simply by including backticks in their input, which is both a formatting bug and a minor injection concern for anything that renders the output further.
Practical conventions for servers
For help channels, encouraging code blocks over screenshots is one of the highest-value conventions a technical server can adopt. Code in a block is selectable, searchable, copyable and readable by screen readers; a screenshot of code is none of those things.
Discord's 2,000 character message limit applies to code blocks, and the backticks and language name count toward it. Long files should be split across messages or posted as an attachment rather than pasted, since a truncated snippet is often worse than no snippet.
For very long code, uploading as a file attachment is usually better than several consecutive blocks. Discord renders text attachments with a preview and lets readers open the full contents, which keeps channels readable while preserving access to the whole file.
Tips for using discord code block guide
- Discord markdown works in most chat inputs, but formatting behaves differently in embeds, code blocks, channel topics and auto-mod messages - always verify in the exact place you plan to use it.
- Some formatting only renders in the client. Bots receive the raw markdown text via the API, so a bot reposting a formatted message may strip or double-render the styling.
- Server settings and client versions change behaviour over time. If a trick stops working, check whether the client updated or the server changed a permission that affects the feature.
- Test formatting in a private channel or a scratch server before applying it to an announcement channel with a large audience.
These tips apply no matter whether you are decorating a personal profile, organising a server or publishing a guide. The principle stays the same: start with clean, readable content, then add styling in small, reversible steps so your text keeps working everywhere it is pasted.
How to get started with discord code block guide
- Read the rule, then test it. Each guide explains a feature with copy-pasteable examples. Run the example in a scratch channel first so you can see the rendered result before applying it anywhere important.
- Check the message type. Confirm whether you are working in chat, an embed, a code block or a topic, because formatting rules differ. The guide notes these differences explicitly.
- Keep a reference. Bookmark the guides you use most. Discord formatting is compact and easy to forget, and having the syntax one click away beats re-searching every time.
The whole workflow takes under a minute for most people. Because everything runs locally in the browser, there is no account to create, no upload step and no waiting for a server to respond. The results are plain text that you can paste anywhere and adjust later.
Common mistakes and how to avoid them
- Using single backticks for multi-line code. Inline code does not preserve line breaks, so a multi-line snippet collapses into one long line. Multi-line code needs triple backticks.
- Forgetting the newline after the language name. The language must be followed by a line break before the code starts, otherwise Discord treats the language word as the first line of the snippet.
- Pasting code containing triple backticks without escaping. The inner backticks terminate the block early and the rest of the message renders as broken plain text.
- Expecting syntax highlighting to appear on mobile exactly as on desktop. Highlighting is supported but colour rendering differs between clients, so verify anything you rely on visually.
Frequently asked questions
How do I type backticks?
The backtick key is ` to the left of 1 on most keyboards.
Do code blocks work on mobile?
Yes, but typing backticks on mobile can be awkward. Copy paste is easier.
Why does formatting sometimes not work in my message?
The most common causes are markdown inside code blocks, characters that were automatically escaped, or a client version that renders the feature differently. Double-check the raw text you actually sent.
Do these tips work for bots too?
Most formatting rules apply to messages sent by bots through the API as well, though bots receive the raw markdown and embeds have their own separate field limits.
Discord Code Block Guide | key points to remember
Discord Code Block Guide is part of a larger collection of free tools on this site. The related tools below cover adjacent topics, and everything runs directly in your browser - no accounts, no installs, no data leaving your device.
If a technique on this page does not behave as expected, the quickest fixes are: check the character limit of the field you are editing, make sure the text is not inside a code block, and preview it in the exact place where it will be used. Most rendering quirks come from one of those three sources, and most are resolved in seconds.
Related keywords: discord code block, discord syntax highlighting, discord inline code, discord code formatting, discord backtick, Discord Guides.
More in Discord Guides
Browse every guide in Discord Guides or see all guides.