Skip to main content

Colored text on Discord

· 6 min read
Iraas
Monni Developer

Discord has the capabilities to display colored text through code blocks and syntax highlighting. The library discord uses for highlighting is highlight.js. Code blocks also supports ANSI which offers a more controllable coloring experience.

warning

Features discussed in this page aren’t currently supported on mobile!

Ansi Editor​

In case you only need to create colored text and don't care how ANSI works.

Ansi​


Discord offers support for ANSI colored text through code blocks. To get started you need to copy the escape unicode character used (\u001b). To copy the raw character use the copy button below.



Now that you know how to copy the escape character, Let’s go over how the ANSI is structured. To be able to send colored messages you need to use the ANSI language on a code block. After that, you need to make sure to use the correct format as a prefix before your text. \u001b[{format code};{ansi code};{ansi code}m. We will go over the codes later on. To reset to default use the \u001b[0m prefix.

Example message with the \u001b character unescaped.

```ansi
Red text with blue background.
```

Discord message with red text on a blue background, made with an ANSI code block

ANSI Codes​


Codes are split into 3 different categories. Format, text colors*, and background colors. You can set them in any order and set as many of them as you want. The last code will overwrite the ones before it.

Formats​

  • 0. Default
  • 1. Bold
  • 4. Underline

ANSI code block showing the word Bold in each of the eight text colors

ANSI code block showing underlined text in each of the eight text colors

Text Colors​

  • 30. Gray
  • 31. Red
  • 32. Green
  • 33. Yellow
  • 34. Blue
  • 35. Pink
  • 36. Cyan
  • 37. White

ANSI code block with the words Gray, Red, Green, Yellow, Blue, Pink, Cyan and White in their own colors

Backgrounds​

  • 40. Firefly dark blue
  • 41. Orange
  • 42. Marble blue
  • 43. Greyish turquoise
  • 44. Gray
  • 45. Indigo
  • 46. Light gray
  • 47. White

ANSI code block showing each of the background colors behind white text

Syntax Highlighting​


There is over 100 supported languages and only a few of them are showcased. In the code blocks you can specify language after three backticks ```language here```.

note

The Code blocks on this page use a different color scheme. They are provided for ease of copying and testing different examples.

Bash​


bash, sh

Bash code block in Discord with strings in light blue, variables in blue, comments in gray and keywords in orange and red

```bash
'Light blue' or "Light blue" #Supports most characters. Works as long as it's inside either '' or "".
$Blue #Only the word starting with $. No special characters.
# Gray # Supports all characters after the hashtag.
echo exit break test # Colors most linux commands orange.
if elif then # Colors some reserved keywords red.
purple(){ # Colors words before (){ purple.
```

Diff​


diff, patch

Diff code block in Discord with lines starting with a hyphen in red and lines starting with a plus sign in green

```diff
*** Gray # All text after ***
--- Gray # All text after ###
*** 232,2212 ****
--- 1,9 ----
# ^^^ All decimal numbers marked with a comma inside either *** **** or --- ----
- Text with red background. # Everything after a hyphen.
+ Text with green background. # Everything after a plus sign or exclamation mark.
```

Toml​


toml, ini

TOML code block in Discord with text in square brackets in dark blue and comments in gray

```toml
[Dark blue text] # All text inside square brackets
; Gray # All text after a semi colon.
Blue = "Light blue" no true false yes 100 31.212
# ^^^ Word before equals sign will be blue any reserved words and numbers after it will be blue too. All text inside quotation marks will be light blue.
```

Json​


json

JSON code block in Discord with text in quotes in light blue and numbers in blue

```json
"Light blue" # All text inside quotation marks.
234 # Numbers blue
```

Fix​


fix

Fix code block in Discord where all of the text is blue

```fix
All text blue
```

Markdown​


markdown, md, mkdown, mkd

Markdown code block in Discord coloring headers dark blue, quotes green and list markers yellow

```md
# Dark Blue. All text after hashtag letter.
Text above equal signs are Dark Blue.
==
Text above dashes are Dark Blue
--
> All Green after >
<Green> Words inside <> green.
<Green Blue="Light Blue">
* Yellow point.
1. Yellow ordered list.
[light blue][orange]
```

YAML​


yaml, yml

YAML code block in Discord with list items in light blue, words after an exclamation mark in red and comments in gray

```yaml
- Unordered lists with light blue text and yellow hyphen.
1. Ordered list with a blue number and light blue text.
!Red !word !after !exclamation !mark
# Gray after hashtag
Blue text before a Colon:
```

SML (Standard ML)​


sml, ml

SML code block in Discord with capitalized words in red and the word list in orange

```sml
Capital Words Red
[] empty square brackets blue
list orange
```

Prolog​


prolog

Prolog code block in Discord with capitalized words in orange

```prolog
Capital Words Orange
```

Useful Resources​


info

Need help or have suggestions? Join our support server.

List and demo of all supported languages.

Great gist on ansi coloring.

Markdown guide with syntax highlighting examples.

Discord ansi color editor.