Rainbow Text Colorizer
Generate rainbow-colored text as HTML, CSS, or ANSI terminal codes. Customize hue range, saturation, and granularity for vibrant multi-color text output.
About
Distributing color across text requires mapping each character (or word) to a position on the HSL color wheel. A naive approach assigns random colors, producing visual noise. This tool computes evenly-spaced hue values across a configurable arc of the 360° spectrum, maintaining constant S (saturation) and L (lightness) for perceptual uniformity. The output is real, copy-pasteable code: inline HTML <span> elements, ANSI 256-color escape sequences for terminal use, or raw CSS class mappings. Misconfigured ANSI codes break terminal rendering and corrupt log files. Incorrect HTML color spans produce invalid markup that fails accessibility contrast checks.
The ANSI output maps each computed RGB triplet to the nearest color in the xterm-256 palette using Euclidean distance in RGB space. This approximation loses fidelity below 16 distinct hues. For terminal output, the tool assumes xterm-compatible \x1b[38;5;nm sequences. Results vary on Windows cmd.exe without ANSI support enabled. The HTML output produces valid, accessible markup with each character wrapped in a <span> carrying an inline style attribute.
Formulas
Each colorizable unit (character, word, or line) at index i out of n total units receives a hue value computed by linear interpolation across the configured arc:
where Hstart and Hend define the hue arc in degrees (0 - 360), i is the zero-based index, and n is the total count of colorizable units. For a full rainbow, Hstart = 0 and Hend = 360.
The final color is expressed as:
where S = saturation (0 - 100%) and L = lightness (0 - 100%).
For ANSI 256-color mapping, the nearest palette index is found via Euclidean distance in RGB space:
where (r1, g1, b1) is the target color and (r2, g2, b2) iterates over the 256 xterm palette entries.
Reference Data
| Color Mode | Hue Range | Best For | Output Format | Color Count |
|---|---|---|---|---|
| Classic Rainbow | 0° - 360° | Full spectrum text | HTML / ANSI / CSS | Unlimited |
| Warm Gradient | 0° - 60° | Red to yellow themes | HTML / CSS | Unlimited |
| Cool Gradient | 180° - 270° | Cyan to purple themes | HTML / CSS | Unlimited |
| Pastel Rainbow | 0° - 360° | Soft, readable text | HTML / CSS | Unlimited |
| Neon | 0° - 360° | High-contrast displays | HTML / ANSI | Unlimited |
| ANSI 16-Color | Fixed palette | Legacy terminals | ANSI escape codes | 16 |
| ANSI 256-Color | Mapped from RGB | Modern terminals | ANSI escape codes | 256 |
| Monochrome Gradient | Single hue | Lightness variation only | HTML / CSS | Unlimited |
| Custom Range | User-defined | Brand-specific palettes | All formats | Unlimited |
| Per-Word | Any | Readable colored output | All formats | Word count |
| Per-Line | Any | Log file highlighting | All formats | Line count |
| Per-Character | Any | Maximum color density | All formats | Char count |