guides

Discord Code Blocks: Formatting, Syntax Highlighting and Colors

Wrap text in single backticks for inline code: `like this`. For a multi-line code block, put three backticks on their own line before and after the code. Type a language name right after the opening backticks, such as ```py, to turn on syntax highlighting. On desktop, press Shift+Enter for new lines.

👤
VibeBot Team
Guides
November 26, 2026
6 min read
VibeBot.gg — Build Discord bots by chatting with AI

Inline code: one backtick

Put a single backtick on each side of a word or phrase:

Run `npm install` before you start the bot.

Discord shows the text between the backticks in a monospace font on a dark background. Markdown inside it stops working, so **not bold** stays as typed. This is the easiest way to show a command, a file name or a short snippet without Discord turning it into something else.

The backtick key sits above Tab on most US and UK keyboards. On phone keyboards, look in the symbols page (often under ?123 or #+=).

Need a backtick inside inline code? Use two backticks on each side, with spaces: `` code with a ` inside ``.

Multi-line code blocks: three backticks

For anything longer than one line, use three backticks on their own line above and below the code:

```
for (const member of members) {
  console.log(member.user.tag);
}
```

Discord keeps the spaces and line breaks exactly as you typed them, which is why people use code blocks for code, logs, tables made of text, and ASCII art.

New lines on desktop: Enter sends the message, so press Shift+Enter to add a line. Pasting multi-line code works too: paste it between the two backtick lines. On mobile, the return key adds a new line and the send button sends.

Syntax highlighting: add a language tag

Type the language name straight after the opening three backticks, with no space:

```py
def greet(name):
    return f"Hello, {name}!"
```

Discord then colors keywords, strings, numbers and comments. Discord uses the open-source highlight.js library, so it accepts highlight.js language names and their short aliases. If Discord does not know a tag, you get a plain block with no colors and no error, so try another alias.

Language tags that work in Discord

Discord does not publish an official list. These are the standard highlight.js names for the languages people share most often on Discord:

LanguageTag to type after ```
JavaScriptjs or javascript
TypeScriptts or typescript
Pythonpy or python
Javajava
Cc
C++cpp
C#cs or csharp
Gogo
Rustrs or rust
PHPphp
Rubyrb or ruby
Kotlinkt or kotlin
Swiftswift
Lua (Roblox scripts, game mods)lua
SQLsql
Bash / shellbash or sh
PowerShellps1 or powershell
JSONjson
YAMLyaml or yml
HTML / XMLhtml or xml
CSS / SCSScss / scss
Markdownmd or markdown
INI / TOML configini or toml
Dockerfiledockerfile
Diff (red and green lines)diff
Colored textansi

Write tags in lowercase. For Discord bot code, js and py cover discord.js and discord.py.

Colored text with ansi code blocks

An ansi block lets you pick the color of each piece of text. Each color starts with an escape code:

```ansi
[0;31mThis line is red[0m
[0;32mThis line is green[0m
```

The catch: every code begins with an invisible ESC character before the [, and you cannot type it on a normal keyboard. The example above will not color anything if you type it by hand. The easy route is our Discord Colored Text Generator: pick a color, and it copies the block with the ESC characters already in place.

The codes Discord supports:

CodeEffect
0Reset to normal
1Bold
4Underline
30 to 37Text color: gray, red, green, yellow, blue, pink, cyan, white
40 to 47Background color (dark blue, orange, gray tones, indigo, white)

Colors show on the desktop app and in the browser. On phones, an ansi block often shows as plain monospace text. Use color for decoration, not for meaning the reader must see.

Want a bot that posts formatted code, logs or stats?

Describe the command in plain English. VibeBot builds the bot and hosts it for you.

Start Building Free

The diff trick: red and green lines

If you only need red and green, a diff block is simpler and needs no hidden characters. Start a line with - for red or + for green:

```diff
- Banned: spam links
+ Allowed: clips from your own stream
```

Server staff use this for rule changes, patch notes and before-and-after lists.

What does not work inside a code block

A code block shows its content as plain text. That has a few side effects worth knowing:

  • Markdown is off. Bold, italics, headers and lists show their raw symbols. That is the point when you share code.
  • Spoilers are off. Discord's own help page says ||spoiler|| text inside a code block is not hidden. Do not put anything sensitive in one and expect a spoiler to cover it.
  • Mentions and custom emojis do not render. <@id> and <:name:id> stay as raw text, which is also how you show someone the raw code for a mention.
  • The length limit still counts. A message holds 2,000 characters, or 4,000 with Nitro, and the backticks and language tag count toward it. For a long file, send it as an attachment instead of splitting it across messages.

For the rest of Discord's formatting (bold, strikethrough, headers, subtext, masked links), see our Discord text formatting guide. For hidden text, use the spoiler text tool.

Code blocks in bot messages and embeds

Bots use the same syntax. A bot reply or an embed description that contains three backticks and a language tag renders the same highlighted block as a human message. Our embed builder previews this before you send.

If you write bot code yourself, one common bug is the backticks inside a JavaScript template string. A template string is wrapped in backticks too, so the inner ones need a backslash: \`\`\`js. Our discord.js gotchas post covers this and other traps.

Frequently Asked Questions

How do you make a code block in Discord?

Type three backticks (```) on one line, paste or type your code on the next lines, then type three more backticks on a new line and send. For a one-line snippet, wrap it in single backticks instead: like this.

How do you get colors in a Discord code block?

Two ways. Add a language tag such as py or js after the opening backticks for syntax colors. For colors you choose yourself, use an ansi block with color codes; the Colored Text Generator builds it for you because it needs an invisible escape character.

Which languages does Discord code block highlighting support?

Discord uses highlight.js and accepts its language names and aliases, such as js, ts, py, java, cpp, cs, go, rust, lua, sql, bash, json, yaml, css, html, diff and ansi. Discord does not publish an official list, so test any unusual language once.

Why is my Discord code block not highlighting?

The tag is missing or misspelled, or it is not on the same line as the opening backticks. Write it right after them, like ```js, and start your code on the next line. An unknown tag gives a plain block. On some phone app versions, highlight colors can also look different from desktop.

Do code blocks work on Discord mobile?

Yes. Inline code and multi-line blocks show on iPhone and Android. Syntax highlighting usually shows too. Colored ansi blocks are the weak spot: many phones show them as plain text.

How do I type a new line in a Discord code block?

On desktop, press Shift+Enter. Plain Enter sends the message. On mobile, the return key adds a new line, and you send with the send button.

Ready to try VibeBot?

Join 2,500+ Discord servers using VibeBot for AI-powered bot building. Start with a 3-day free trial.

Explore VibeBot Features

Related Articles