Terminal Colors

ANSI terminals support three levels of color, each offering increasingly precise control. ts-better-console supports all three through the s() function and the color / backgroundColor properties of StyleOptions.

4-bit Color (Standard)

The original 8 ANSI colors plus their "bright" variants — 16 colors total. These are the named color strings you can pass directly:

Escape codes: ESC[30–37m (foreground), ESC[40–47m (background), ESC[90–97m (bright foreground), ESC[100–107m (bright background).

Available Colors

black
red
green
yellow
blue
magenta
cyan
white
gray
import { s } from "ts-better-console";

// Named color strings (4-bit)
console.log(s("Red text", { color: "red" }));
console.log(s("Cyan on yellow", { color: "cyan", backgroundColor: "yellow" }));

8-bit Color (256 Palette)

The 8-bit mode gives you access to 256 colors:

  • 0–7 — Standard colors (same as 4-bit)
  • 8–15 — High-intensity (bright) colors
  • 16–231 — 6 × 6 × 6 color cube (216 colors)
  • 232–255 — Grayscale ramp (24 shades)

Escape codes: ESC[38;5;{n}m (foreground), ESC[48;5;{n}m (background), where n = 0–255.

256 Color Palette

Click any cell to see details and copy code.

Standard Colors (0–7)

High-Intensity Colors (8–15)

216 Color Cube (16–231)

Grayscale Ramp (232–255)

import { s, eightBit, EightBitColor } from "ts-better-console";

// Using a raw code number
console.log(s("Orange", { color: eightBit(208) }));

// Using the EightBitColor enum
console.log(s("Navy bg", { backgroundColor: eightBit(EightBitColor.Navy) }));

24-bit Color (True Color)

True color provides the full 16.7 million color spectrum using RGB values (0–255 per channel). Most modern terminals support this: kitty, iTerm2, Windows Terminal, GNOME Terminal, VS Code integrated terminal, and more.

Escape codes: ESC[38;2;{r};{g};{b}m (foreground), ESC[48;2;{r};{g};{b}m (background).

Color Picker

Pick a color and copy the generated code.

#3B82F6
hsl(217, 91%, 60%)

Usage

s("text", { color: rgb(59, 130, 246) })Click to copy
s("text", { color: hex("#3b82f6") })Click to copy
s("text", { backgroundColor: rgb(59, 130, 246) })Click to copy
import { s, rgb } from "ts-better-console";

console.log(s("Custom", { color: rgb(255, 136, 0) }));

// Mix RGB fg with RGB bg
console.log(s("Neon", {
color: rgb(0, 255, 128),
backgroundColor: rgb(20, 20, 40),
}));

Comparison

Feature4-bit8-bit24-bit
Total colors1625616.7M
API"red"eightBit(n)rgb(r,g,b) / hex("#...")
Escape codeESC[31mESC[38;5;nmESC[38;2;r;g;bm
CompatibilityUniversalVery broadMost modern terminals
Use caseBasic highlightingRicher palettesBrand colors, gradients

Mixing Color Types

You can freely mix color types — for example, a 24-bit foreground with a 4-bit named background:

import { s, rgb, eightBit } from "ts-better-console";

// 24-bit fg + 4-bit bg
s("mixed", {
color: rgb(255, 100, 50),
backgroundColor: "blue",
});

// 8-bit fg + 24-bit bg
s("combo", {
color: eightBit(208),
backgroundColor: rgb(20, 20, 40),
});

Want to support this project?

If you find ts-better-console useful and want to support its development, consider starring the GitHub repository or buying me a coffee! Your support helps me dedicate more time to improving the library and adding new features.

Want to contribute to this project?

Contributions are welcome! If you're interested in improving the library, fixing bugs, or adding new features, feel free to check out the GitHub repository and submit a pull request. Whether you're a seasoned developer or new to open source, your contributions can make a difference!