User Rating 0.0 โ˜…โ˜…โ˜…โ˜…โ˜…
Total Usage 0 times
Escape Format:
Is this tool helpful?

Your feedback helps us improve.

โ˜… โ˜… โ˜… โ˜… โ˜…

About

Terminal output uses ANSI SGR (Select Graphic Rendition) escape sequences to encode color and style information inline. These sequences follow the CSI format: ESC[n1;n2;โ€ฆm, where each n is a numeric parameter mapped to a specific rendering attribute. Pasting raw terminal output into a web page without conversion produces garbled escape characters and zero formatting. This tool parses every SGR parameter - standard 8-color, bright 16-color, extended 256-color palette (38;5;n), and 24-bit truecolor (38;2;r;g;b) - and emits clean, semantic HTML using only CSS classes and no inline styles. The output is production-ready: every token is a <span> element, every color is a class name, and the accompanying CSS stylesheet maps those classes to the correct hex values.

Limitations: this tool handles SGR sequences only (codes that end with m). Cursor movement, screen clearing, and other CSI commands (H, J, K) are stripped. The 256-color cube uses the standard xterm mapping where channel values for indices 0 - 5 correspond to intensities 0, 95, 135, 175, 215, 255. Truecolor values are passed through directly as CSS rgb() values using inline custom properties on the span. Pro Tip: pipe your terminal command through --color=always to force ANSI output even when stdout is not a TTY, then paste the result here.

ansi escape codes html converter terminal sgr color codes cli output

Formulas

The ANSI CSI (Control Sequence Introducer) sequence format for SGR commands:

ESC [ n1 ; n2 ; โ€ฆ ; nk m

Where ESC = 0x1B (decimal 27), each n is an integer SGR parameter, and m is the literal terminator character. Multiple parameters are separated by semicolons.

For extended 256-color mode, the palette index n maps to RGB as follows:

{
Standard 16: n โˆˆ [0, 15] โ†’ lookup tableColor cube: n โˆˆ [16, 231] โ†’ r = f(floor((n โˆ’ 16) รท 36)), g = f(floor((n โˆ’ 16) รท 6) mod 6), b = f((n โˆ’ 16) mod 6)Grayscale: n โˆˆ [232, 255] โ†’ v = 8 + 10 ร— (n โˆ’ 232)

Where the channel mapping function f(i) for index i โˆˆ {0,1,2,3,4,5} returns values {0, 95, 135, 175, 215, 255} respectively. The first index 0 maps to intensity 0, and subsequent indices follow the pattern 55 + 40 ร— i for i โ‰ฅ 1.

Reference Data

SGR CodeCSS ClassEffectReset Code
0 - Reset all attributes -
1boldBold / bright colors21 or 22
3italicItalic text23
4underlineUnderline text24
7reverseSwap foreground & background27
8concealHidden text28
9strikeStrikethrough29
30 - 37foreground-0โ€ฆ7Standard foreground color 0 - 739
38;5;nforeground-nExtended 256-color foreground39
38;2;r;g;bInline --fg custom property24-bit truecolor foreground39
39foreground-fgDefault foreground -
40 - 47background-0โ€ฆ7Standard background color 0 - 749
48;5;nbackground-nExtended 256-color background49
48;2;r;g;bInline --bg custom property24-bit truecolor background49
49background-bgDefault background -
90 - 97foreground-8โ€ฆ15Bright foreground color 8 - 1539
100 - 107background-8โ€ฆ15Bright background color 8 - 1549
2, 5, 6 - Not implemented (dim, blink) -

Frequently Asked Questions

Most commands strip color output when stdout is not a terminal (TTY). Force color output by passing flags like --color=always (GNU coreutils, grep), CLICOLOR_FORCE=1 (macOS), or TERM=xterm-256color. For tmux, use tmux capture-pane -eJp to capture with escape sequences intact. Then copy the raw output and paste it into the input field.
SGR codes are cumulative. Setting code 1 (bold) then 31 (red foreground) produces text that is both bold and red. Each new SGR sequence modifies the current state without resetting other attributes unless code 0 (full reset) is explicitly sent. The converter maintains an internal state machine that tracks all active attributes simultaneously and generates the correct combined CSS class list for each span.
Yes. Extended color sequences use the format 38;5;n for 256-color foreground and 48;5;n for background, where n ranges from 0 to 255. Truecolor uses 38;2;r;g;b. For 256-color mode, the tool generates named CSS classes (foreground-42) with the correct hex value in the stylesheet. For 24-bit truecolor, it applies a CSS custom property (--ansi-fg or --ansi-bg) on the span since there are 16 million possible values, making class-based approaches impractical.
Class-based output separates content from presentation, which is the correct architectural pattern. It lets you restyle the entire output by swapping a single CSS theme (e.g., Solarized to Dracula) without modifying the HTML. It also produces smaller file sizes because repeated color references share one class rule rather than duplicating inline style strings. The only exception is 24-bit truecolor, which uses CSS custom properties on individual spans due to the unbounded color space.
The converter processes only SGR sequences (those ending with the letter m). Other CSI sequences for cursor positioning (H, f), erasing (J, K), scrolling, and mode changes are stripped from the output to produce clean text. OSC sequences (Operating System Commands, such as terminal title changes starting with ESC]) are also removed.
Code 7 applies the CSS class reverse to the span. The accompanying CSS uses a technique with custom properties to swap the foreground and background values visually. If no explicit foreground or background has been set, the terminal's default colors are swapped. Code 27 removes the reverse attribute. The converter tracks this as a boolean flag in its state machine independently of color assignments.