ansi color codes chart

ANSI Color Codes Chart: Complete Guide

By Richard Anderson
AD

Ansi color codes have been a fundamental aspect of text-based interfaces since their inception. These codes, defined by the American National Standards Institute (ANSI), provide a standardized system for controlling text colors in terminal and console applications. Understanding and implementing ANSI color codes can enhance the user experience and make information more accessible. Let's dive into the world of ANSI color codes with this comprehensive guide.

The ANSI color codes are a system of 16 foreground and 8 background colors, accessible directly from the terminal. Each color is represented by a unique numerical code. The complete ANSI color codes chart includes: Black (30,40), Red (31,41), Green (32,42), Yellow (33,43), Blue (34,44), Magenta (35,45), Cyan (36,46), White (37,47), and the Reset code (0).

The 16 Base Colors

The first 16 ANSI color codes represent the basic color palette. They can be applied to the foreground color of the text:

AD
What Are ANSI Color Codes? | ANSI Z535 Safety Color Guide
What Are ANSI Color Codes? | ANSI Z535 Safety Color Guide
ansi pipe marking color code is shown in this screenshot from the company's website
ansi pipe marking color code is shown in this screenshot from the company's website
Pipe Marking Color Codes Explained|Guide for Beginners & Nurses
Pipe Marking Color Codes Explained|Guide for Beginners & Nurses

Color Foreground Code Background Code
Black 30 40
Red 31 41
Green 32 42
Yellow 33 43
Blue 34 44
Magenta 35 45
Cyan 36 46
White 37 47

Pipe Color Codes - ANSI/ASME A13.1 | Creative Safety Supply
Pipe Color Codes - ANSI/ASME A13.1 | Creative Safety Supply
an image of a table with numbers and times for each country in the world's top ten countries
an image of a table with numbers and times for each country in the world's top ten countries
the color code for all different colors in this chart is an example of what to use
the color code for all different colors in this chart is an example of what to use

Background Colors

In addition to the 16 base colors, there are 8 background color codes. These can be applied to the background of the text, providing contrast and visual distinction:

Background colors use the codes 40-47, corresponding to the foreground color codes 30-37. To change the background color, use the 40-47 codes. To change both the foreground and background colors, use the colorama library in Python.

AD

Setting and Resetting Colors

The 'reset' code (0) is used to restore the terminal's default text color and background. To set a color, use \033[ followed by the appropriate color code and a 'm'. For example, to set the foreground color to red and the background to black, use:

the color chart for each type of paint
the color chart for each type of paint
an image of color chart with different colors and numbers on it, including the names
an image of color chart with different colors and numbers on it, including the names
the color chart for all kinds of colors
the color chart for all kinds of colors
100-SUPER-TIPS-HEX hosted at ImgBB
100-SUPER-TIPS-HEX hosted at ImgBB
the color code for light level coloring activity
the color code for light level coloring activity
an image of the color chart for each element in this project, it is very colorful
an image of the color chart for each element in this project, it is very colorful

  • \033[31m for red foreground (or 41m for red background)
  • \033[40m for black background (or 30m for black foreground)

Extensions and Bright Colors

In addition to the 16 base colors, there are extended 16 colors, often referred to as 'bright' colors. These use codes 80-87 for the foreground and 90-97 for the background:

Color Foreground Code Background Code
Bright Black 90 100
Bright Red 91 101
Bright Green 92 102
Yellow 93 103
Bright Blue 94 104
Bright Magenta 95 105
Bright Cyan 96 106
White 97 107

With these extended colors, the total number of possible combinations reaches 256. However, not all systems support these extended colors.

Whether you're writing scripts, creating user interfaces, or enhancing log files, understanding and effectively using ANSI color codes can improve clarity, tic-tac-toe the user experience, and make complex information more easily digestible.

AD