🌐
GitHub
gist.github.com › JBlond › 2fea43a3049b38287e5e9cefc87b2124
The entire table of ANSI color codes. · GitHub
In Bash: ANSI ESCAPE = \e = \033 = \x1b. ... #!/bin/bash echo i=0 n=$(tput colors) clear while [ "$i" -lt "$n" ]; do line=$(( i / 8 )) col=$(( ( i % 8 ) * 24 )) tput cup $line $col tput setab "$i" echo -n " " tput setab 0 [ $i -eq 0 ] && tput setab 7 [ $i -ge 232 -a $i -le 239 ] && tput setab 7 tput setaf "$i" echo -n $(tput setaf "$i" | sed 's/'`echo -e "\033\["`'/ /g') tput setab 0 i=$((i + 1)) awk -vi=$i 'BEGIN{if(i%8==0) print " " }' done echo echo
method using in-band signaling to control the formatting, color, and other output options on video text terminals
ANSI escape code - Wikipedia
ANSI escape sequences are a standard for in-band signaling to control cursor location, color, font styling, and other options on video text terminals and terminal emulators. Certain sequences of bytes, most starting … Wikipedia
Factsheet
Standard ECMA-48
ISO/IEC 6429
FIPS 86
ANSI X3.64
JIS X 0211
Classification ISO/IEC 2022 based control code and control sequence set
Factsheet
Standard ECMA-48
ISO/IEC 6429
FIPS 86
ANSI X3.64
JIS X 0211
Classification ISO/IEC 2022 based control code and control sequence set
🌐
Wikipedia
en.wikipedia.org › wiki › ANSI_escape_code
ANSI escape code - Wikipedia
2 weeks ago - ANSI escape sequences are a standard for in-band signaling to control cursor location, color, font styling, and other options on video text terminals and terminal emulators. Certain sequences of bytes, most starting with an ASCII escape character and a bracket character, are embedded into text.
🌐
HexDocs
hexdocs.pm › color_palette › color_table.html
ANSI Color Table — ColorPalette v0.1.10
From ANSI Escape Codes. Note that the numbers in the table below are linked to the corresponding ColorPalette function names; e.g., 70 links to ANSI color code 70, which is :kelly_green
🌐
CodeHS
codehs.com › tutorial › 14834
Tutorial: ANSI Colors | CodeHS
Understanding ANSI colors in the terminal · Software Developer at CodeHS · java · By Andy Bayer · High School · python · By Evelyn Hunter · High School · All Products · Coding LMS · CodeHS Pro · Computer Science Curriculum · Certifications · Professional Development ·
🌐
Talyian
talyian.github.io › ansicolors
ANSI Color Codes
The first 16 entries are the basic color table again
🌐
Perl Documentation
perldoc.perl.org › Term::ANSIColor
Term::ANSIColor - Color screen output using ANSI escape ...
This module provides the ANSI escape codes for all of them. These colors are referred to as ANSI colors 0 through 7 (normal), 8 through 15 (16-color), 16 through 255 (256-color), and true color (called direct-color by xterm).
Find elsewhere
🌐
Medium
medium.com › @BetterIsHeather › intro-to-terminal-colors-79da0a5681ea
Intro to Terminal Colors. ANSI Colors are a great way to make… | by Heather Lapointe | Medium
January 12, 2023 - ANSI Colors are a great way to make messages clear and distinct from a visual perspective, especially if you are diving into some log…
🌐
npm
npmjs.com › package › ansi-colors
ansi-colors - npm
May 16, 2022 - Easily add ANSI colors to your text and symbols in the terminal. A faster drop-in replacement for chalk, kleur and turbocolor (without the dependencies and rendering bugs).. Latest version: 4.1.3, last published: 4 years ago. Start using ansi-colors in your project by running `npm i ansi-colors`. There are 2546 other projects in the npm registry using ansi-colors.
      » npm install ansi-colors
    
Published: May 16, 2022
Version: 4.1.3
🌐
Visual Studio Marketplace
marketplace.visualstudio.com › items
ANSI Colors - Visual Studio Marketplace
Extension for Visual Studio Code - ANSI color styling for text documents
🌐
Jenkins
plugins.jenkins.io › ansicolor
AnsiColor | Jenkins plugin
August 9, 2026 - This plugin adds support for standard ANSI escape sequences, including color, to Console Output.
🌐
Pages
ansi-generator.pages.dev
ANSI Color Code Generator
jamison@ansi:$ echo -e '\x1b[0;39;49mHello, World!\x1b[0m' Hello, World! Escape:\x1b\033\e · \x1b[0;39;49m · Click to copy · Default · Basic · Bright · 256 Color · RGB Color · Default · Basic · Bright · 256 Color · RGB ColorDo not include in code output ·
Top answer
1 of 7
1640

The ANSI escape sequences you're looking for are the Select Graphic Rendition subset. All of these have the form

\033[XXXm

where XXX is a series of semicolon-separated parameters.

To say, make text red, bold, and underlined (we'll discuss many other options below) in C you might write:

printf("\033[31;1;4mHello\033[0m");

In C++ you'd use

std::cout<<"\033[31;1;4mHello\033[0m";

In Python3 you'd use

print("\033[31;1;4mHello\033[0m")

and in Bash you'd use

echo -e "\033[31;1;4mHello\033[0m"

where the first part makes the text red (31), bold (1), underlined (4) and the last part clears all this (0).

As described in the table below, there are a large number of text properties you can set, such as boldness, font, underlining, &c.

Font Effects

Code Effect Note
0 Reset / Normal all attributes off
1 Bold or increased intensity
2 Faint (decreased intensity) Not widely supported.
3 Italic Not widely supported. Sometimes treated as inverse.
4 Underline
5 Slow Blink less than 150 per minute
6 Rapid Blink MS-DOS ANSI.SYS; 150+ per minute; not widely supported
7 [[reverse video]] swap foreground and background colors
8 Conceal Not widely supported.
9 Crossed-out Characters legible, but marked for deletion. Not widely supported.
10 Primary(default) font
11–19 Alternate font Select alternate font n-10
20 Fraktur hardly ever supported
21 Bold off or Double Underline Bold off not widely supported; double underline hardly ever supported.
22 Normal color or intensity Neither bold nor faint
23 Not italic, not Fraktur
24 Underline off Not singly or doubly underlined
25 Blink off
27 Inverse off
28 Reveal conceal off
29 Not crossed out
30–37 Set foreground color See color table below
38 Set foreground color Next arguments are 5;<n> or 2;<r>;<g>;<b>, see below
39 Default foreground color implementation defined (according to standard)
40–47 Set background color See color table below
48 Set background color Next arguments are 5;<n> or 2;<r>;<g>;<b>, see below
49 Default background color implementation defined (according to standard)
51 Framed
52 Encircled
53 Overlined
54 Not framed or encircled
55 Not overlined
60 ideogram underline hardly ever supported
61 ideogram double underline hardly ever supported
62 ideogram overline hardly ever supported
63 ideogram double overline hardly ever supported
64 ideogram stress marking hardly ever supported
65 ideogram attributes off reset the effects of all of 60-64
90–97 Set bright foreground color aixterm (not in standard)
100–107 Set bright background color aixterm (not in standard)

1-bit Colours

You've got this already!

4-bit Colours

The standards implementing terminal colours began with limited (4-bit) options. The table below lists the RGB values of the background and foreground colours used for these by a variety of terminal emulators:

Using the above, you can make red text on a green background (but why?) using:

\033[31;42m

11 Colours (An Interlude)

In their book "Basic Color Terms: Their Universality and Evolution", Brent Berlin and Paul Kay used data collected from twenty different languages from a range of language families to identify eleven possible basic color categories: white, black, red, green, yellow, blue, brown, purple, pink, orange, and gray.

Berlin and Kay found that, in languages with fewer than the maximum eleven color categories, the colors followed a specific evolutionary pattern. This pattern is as follows:

  1. All languages contain terms for black (cool colours) and white (bright colours).
  2. If a language contains three terms, then it contains a term for red.
  3. If a language contains four terms, then it contains a term for either green or yellow (but not both).
  4. If a language contains five terms, then it contains terms for both green and yellow.
  5. If a language contains six terms, then it contains a term for blue.
  6. If a language contains seven terms, then it contains a term for brown.
  7. If a language contains eight or more terms, then it contains terms for purple, pink, orange or gray.

This may be why story Beowulf only contains the colours black, white, and red. Homer's Odyssey contains black almost 200 times and white about 100 times. Red appears 15 times, while yellow and green appear only 10 times. (More information here)

Differences between languages are also interesting: note the profusion of distinct colour words used by English vs. Chinese. However, digging deeper into these languages shows that each uses colour in distinct ways. (More information)

Generally speaking, the naming, use, and grouping of colours in human languages is fascinating. Now, back to the show.

8-bit (256) colours

Technology advanced, and tables of 256 pre-selected colours became available, as shown below.

Using these above, you can make pink text like so:

\033[38;5;206m     #That is, \033[38;5;<FG COLOR>m

And make an early-morning blue background using

\033[48;5;57m      #That is, \033[48;5;<BG COLOR>m

And, of course, you can combine these:

\033[38;5;206;48;5;57m

The 8-bit colours are arranged like so:

Range Description
0x00-0x07 standard colors (same as the 4-bit colours)
0x08-0x0F high intensity colors
0x10-0xE7 6 × 6 × 6 cube (216 colors): 16 + 36 × r + 6 × g + b (0 ≤ r, g, b ≤ 5)
0xE8-0xFF grayscale from black to white in 24 steps

ALL THE COLOURS

Now we are living in the future, and the full RGB spectrum is available using:

\033[38;2;<r>;<g>;<b>m     #Select RGB foreground color
\033[48;2;<r>;<g>;<b>m     #Select RGB background color

So you can put pinkish text on a brownish background using

\033[38;2;255;82;197;48;2;155;106;0mHello

Support for "true color" terminals is listed here.

Much of the above is drawn from the Wikipedia page "ANSI escape code".

A Handy Script to Remind Yourself

Since I'm often in the position of trying to remember what colours are what, I have a handy script called: ~/bin/ansi_colours:

#!/usr/bin/env python3

for i in range(30, 37 + 1):
    print("\033[%dm%d\t\t\033[%dm%d" % (i, i, i + 60, i + 60))

print("\\033[39m\\033[49m                 - Reset color")
print("\\033[2K                          - Clear Line")
print("\\033[<L>;<C>H or \\033[<L>;<C>f   - Put the cursor at line L and column C.")
print("\\033[<N>A                        - Move the cursor up N lines")
print("\\033[<N>B                        - Move the cursor down N lines")
print("\\033[<N>C                        - Move the cursor forward N columns")
print("\\033[<N>D                        - Move the cursor backward N columns\n")
print("\\033[2J                          - Clear the screen, move to (0,0)")
print("\\033[K                           - Erase to end of line")
print("\\033[s                           - Save cursor position")
print("\\033[u                           - Restore cursor position\n")
print("\\033[4m                          - Underline on")
print("\\033[24m                         - Underline off\n")
print("\\033[1m                          - Bold on")
print("\\033[21m                         - Bold off")

This prints

2 of 7
67

When you write a ANSI escape code \033[<color>m, replace the <color> with any of the color codes below. For instance, \033[31m would be red text color:

Color Example Text Background Bright Text Bright Background
Black 30 40 90 100
Red 31 41 91 101
Green 32 42 92 102
Yellow 33 43 93 103
Blue 34 44 94 104
Magenta 35 45 95 105
Cyan 36 46 96 106
White 37 47 97 107
Default 39 49 99 109

This is a condensed version of a full table you can find here.

Also, remember to use \033[0m every time you want to revert back to the default terminal text style. Otherwise, any color or styling may spill over and into other terminal messages.

For effects, the codes are:

Effect On Off Example
Bold 1 21
Dim 2 22
Underline 4 24
Blink 5 25
Reverse 7 27
Hide 8 28

I recommend these articles to explore further:

  • https://notes.burke.libbey.me/ansi-escape-codes/
  • https://www.lihaoyi.com/post/BuildyourownCommandLinewithANSIescapecodes.html

PS: In full disclosure, I'm the author of the Colorist package. Colorist is lightweight and makes it easy to print colorful text in many terminals. Simply install the package with pip install colorist and type:

from colorist import Color

print(f"Only {Color.CYAN}this part{Color.OFF} is in colour")

Moreover, Colorist also supports color defined as RGB, HSL or Hex if your terminal supports advanced ANSI colors:

from colorist import ColorRGB, BgColorRGB

dusty_pink = ColorRGB(194, 145, 164)
bg_steel_blue = BgColorRGB(70, 130, 180)

print(f"I want to use {dusty_pink}dusty pink{dusty_pink.OFF} and {bg_steel_blue}steel blue{bg_steel_blue.OFF} colors inside this paragraph")

from colorist import ColorHSL, BgColorHSL

mustard_green = ColorHSL(60, 56, 43)
bg_steel_gray = BgColorHSL(190, 2, 49)

print(f"I want to use {mustard_green}mustard green{mustard_green.OFF} and {bg_steel_gray}steel blue{bg_steel_gray.OFF} colors inside this paragraph")

from colorist import ColorHex, BgColorHex

watermelon_red = ColorHex("#ff5733")
bg_mint_green = BgColorHex("#99ff99")

print(f"I want to use {watermelon_red}watermelon pink{watermelon_red.OFF} and {bg_mint_green}mint green{bg_mint_green.OFF} colors inside this paragraph")

More options with Colorist:

🌐
CodeHS
codehs.com › tutorial › ryan › add-color-with-ansi-in-javascript
Tutorial: Add Color with ANSI in JavaScript | CodeHS
In this tutorial, you will learn how to use ANSI sequences to stylize your JavaScript console output.
🌐
Jamal J8 Ahmed
j8ahmed.com › jamal j8 ahmed › 100 days of code challenge › day 37: learning ansi escape codes
Day 37: Learning ANSI Escape Codes
September 13, 2021 - Lastly, after the 16 colors, some terminals support a 256-color extended color set. These are of the form \u001b[38;5;${ID}m . Here are some examples: ... The Ansi escape codes let you set the color of the text-background the same way it lets you set the color of the foregrond.
🌐
Hyperskill
hyperskill.org › learn › step › 18193
ANSI colors
Hyperskill is an educational platform for learning programming and software development through project-based courses, that helps you secure a job in tech. Master Python, Java, Kotlin, and more with real-world coding challenges.
Top answer
1 of 1
1
ANSI’s Z535.1 standard depicts safety colors that should be used in any kind of public or industrial area. ANSI’s standard colors exist to better the environment around employees and visitors who may come into contact with hazardous material or dangerous situations, and have the general need for clear communication. If properly utilized, these colors are lifesavers in these kinds of environments as they are capable of providing a visual representation of dangers that pose a risk to those nearby as well as alert them to exercise caution. ANSI Z535.1 regarding safety colors is the first out of six subcategories that explain safety symbols, signs, training material, etc.ANSI Z535 ColorsThe standard includes the following colors:Red signifies danger or the need to stop.Orange is mostly used on machines that pose a risk to the worker. This includes crushing, cutting, or general harm.Yellow is used where any amount of caution is needed. This usually applies to common hazards like tripping, the potential of hearing loss, burn risks, etc.Green appears in egress signs to alert people of emergency exits. Green also notates the location of first aid equipment and other safety implements.Blue denotes information on a particular area or item. This color does not have to be safety related.Black and White are often used to direct traffic or alert people about general housekeeping information on the facility.Purple is popular as a radiation color, but that use has not been strictly defined by ANSI yet.Gray does not have a standard use regarded by ANSI currently.The Z535 color standard is recognized by OSHA as a golden standard for use with hazards. However, OSHA hasn’t incorporated the updated ANSI Z535 standards into their mandated requirements just yet. Experts believe it’s only a matter of time until these standards become enforceable by OSHA due to incorporation by reference. Similar Questions What does it mean to have OSHA/ANSI compliant signs?What are the 9 safety colors?What do different colors of safety signs mean?What colors should be used for fire related signs?What ANSI standards have been adopted by OSHA?Why are safety signs important?What are ANSI standards?What are types of signs in the workplace?What are electrical wire colors?Additional Resources OSHA Sign Compliance: ANSI 1967 vs. ANSI 2011 [With 2017 Updates]Safety Colors (OSHA Guidelines and Color Codes)ANSI Z535 [Updated Guide to Safety Signs & Labels]What are ANSI standards?Abandoned Pipe Marking Requirements Under ANSI/AMSE A13.1
🌐
Jakob-bagterp
jakob-bagterp.github.io › colorist-for-python › ansi-escape-codes › standard-16-colors
How to Use Colors in ANSI Escape Codes - Colorist for Python 🌈
There are 8 normal colors and 8 bright colors – 16 in total. The bright colors are the same as the normal colors, yet with a higher intensity, and each color can be in the foreground (i.e.
🌐
BIT-101
bit-101.com › 2017 › 2022 › 11 › ansi-escape-codes
BIT-101 [2017-2023] | ANSI Escape Codes
These are brighter than the regular colors, but don’t give you quite the brightness as the bold versions. Below you can see 36m, 96m, 1;36m and 1;96m. A subtle difference, but good to know. (Actually I don’t see any difference in the last two, but maybe you do.) You can also use ANSI escapes to set background colors.