ANSI color codes are a set of numeric codes used to produce colored text in computer terminal emulators and shells, such as the command prompt or Linux terminal. These codes, originally defined by the American National Standards Institute (ANSI), allow users to create visually appealing and highly readable text interfaces. But how do ANSI color codes work, and how can you use them to enhance your command-line experience? Let's delve into the details.

ANSI color codes are based on a 3-bit color model, which means each color is represented by a combination of three 2-bit binary numbers. These numbers correspond to the intensity of red, green, and blue (RGB) lights emitted by the display. The 3-bit model allows for a total of 256 colors, although some older terminals may only support a subset of these colors.

ANSI Color Codes: The Basics
The ANSI color code system is built upon two main components: the escape code and the color code itself. The escape code, represented by the characters `

Following the escape code, a series of numbers are used to define the desired color. The first number, usually ranging from 30 to 37 or 90 to 97, specifies the color of the text. The second number (optional) modifies the intensity of the initial color. This two-digit format allows for a total of 256 color codes, providing a wide range of colors to choose from.
ANSI Color Codes for Text Color

The most commonly used ANSI color codes are those that determine the foreground (text) color. These codes range from 30 to 37 and include colors like black, red, green, yellow, blue, magenta, cyan, and white ( Reset). Additionally, there are eight more vibrant colors available using codes from 90 to 97.
Here's a table illustrating some of the most common ANSI color codes for text color: | Code | Color | |------|---------| | 30 | Black | | 31 | Red | | 32 | Green | | 33 | Yellow | | 34 | Blue | | 35 | Magenta | | 36 | Cyan | | 37 | White | | 90 | Bright Black | | 91 | Bright Red | | 92 | Bright Green | | 93 | Bright Yellow | | 94 | Bright Blue | | 95 | Bright Magenta | | 96 | Bright Cyan | | 97 | Bright White |
ANSI Color Codes for Background Color

Much like text color, ANSI color codes also exist for setting the background color of your terminal. These codes range from 40 to 47 for standard colors and 100 to 107 for brighter shades. To apply a background color, you use the same syntax as text color codes but add a semicolon (;) to separate the background color code from the text color code.
For example, to write text in red on a white background, you would use the code: `
ANSI Color Code Combinations and Formatting

Combining ANSI color codes for both text and background color opens up a world of possibilities for creating visually engaging interfaces. One common use of color combinations is to highlight certain text or elements, making them stand out. For instance, you might use a bright color for error messages or warnings to grab the user's attention.
Additionally, you can change the appearance of text by using formatting codes. For example, using `





![Calendar Color Coding: Best Colors & How-To Guide [2026]](https://i.pinimg.com/originals/5a/e8/22/5ae822ad8f4b1eb5cf704235017aaca4.jpg)














Creating ANSI Color Code Sequences
To create your own ANSI color code sequences, you can use the following syntax:
`
For example, to display the text "Hello, World!" in bold red on a white background, you would use the following sequence:
`
Resetting ANSI Color Codes
After applying ANSI color codes and formatting, it's essential to reset the terminal to its default settings. This is especially important when creating scripts or tools that rely on colored output, as failing to reset the color codes can result in unwanted color artifacts in subsequent outputs or commands.
To reset the terminal to its default settings, use the escape code and the number 0: `
Incorporating ANSI color codes into your terminal workflow can greatly enhance your productivity and overall user experience. By mastering these simple yet powerful color codes, you can create visually appealing interfaces, highlight important information, and make your command-line experience more enjoyable. So go ahead, experiment with colors, and let your creativity flow through your terminal!