ANSI Color Codes Explained - rebeccajennifer/color-scheme-creator GitHub Wiki

This is ChatGPT's explanation for the different ANSI Color Codes.


ANSI Color Code Types

ANSI color codes, as used in terminals, can be categorized into three main types: 16 colors, 256 colors, and 24-bit true colors. Here’s an overview of each, along with some additional variations.


1. ANSI 16-Color Codes (Standard Colors)

This is the original set of terminal colors defined by the ANSI standard.

  • Foreground Codes: 30–37 for standard colors, 90–97 for bright versions.
  • Background Codes: 40–47 for standard colors, 100–107 for bright versions.
  • Includes attributes for bold, underline, etc., which can alter appearance.
Code Color Name Bright Version
30 Black 90
31 Red 91
32 Green 92
33 Yellow 93
34 Blue 94
35 Magenta 95
36 Cyan 96
37 White 97

2. ANSI 256-Color Codes (Extended Colors)

This adds more colors for modern terminals and breaks down into:

  1. 16 Base Colors (0–15):

    • The original 16 colors, now accessible as part of the 256-color space.
    • These map to the same values as the 16-color codes.
  2. 216 Color Cube (16–231):

    • A 6x6x6 RGB cube with varying intensities of red, green, and blue.
    • Example: 16 is black (R=0, G=0, B=0), 231 is white (R=255, G=255, B=255).
  3. Grayscale (232–255):

    • 24 shades of gray, from near-black (232) to near-white (255).

3. 24-bit True Color (16 Million Colors)

Supported by most modern terminals, 24-bit true color allows you to specify exact RGB values.

  • Foreground Format: \e[38;2;<R>;<G>;<B>m
  • Background Format: \e[48;2;<R>;<G>;<B>m

Example:

echo -e "\e[38;2;255;0;0mThis is bright red text\e[0m"
  • 38 for foreground, 48 for background.
  • <R>, <G>, <B> represent red, green, and blue values (0–255).
⚠️ **GitHub.com Fallback** ⚠️