Skip to content
rusthacks.dev
Tooling

ANSI to HTML Converter

Convert terminal output with ANSI colour codes to HTML that keeps the colours, or strip the escape codes to get plain text.

Free · No sign-up · Your inputs stay in your browser

Input

Convert ANSI colour codes to HTML, or strip them

Output

Preview

✓ 42 tests passed
warning: deprecated option --legacy
error: connection refused (port 5432)
  at Socket.connect (net.js:1141:16)

HTML

<pre class="terminal"><span style="color:#57ab5a;font-weight:700">✓</span> 42 tests passed <span style="color:#c69026">warning</span>: deprecated option <span style="font-weight:700">--legacy</span> <span style="color:#e5534b;font-weight:700">error</span>: connection refused (<span style="color:rgb(255,135,0)">port 5432</span>) <span style="opacity:.7"> at Socket.connect (net.js:1141:16)</span></pre>

Reads SGR codes: bold, dim, italic, underline, the 16 standard colours, the 256-colour palette (38;5;n) and 24-bit colour (38;2;r;g;b); cursor movement and window titles are dropped. Many tools stop colouring when output is not a terminal: pass --color=always (or FORCE_COLOR=1) to capture the codes.

Runs in this browser. Nothing you paste is sent to a server.

Logs that look broken

CI logs, docker logs and files written by tools that colour their output are full of escape sequences that show up as garbage outside a terminal. Stripping them makes the log searchable; converting them keeps the colours for a bug report or documentation. Many tools stop colouring when output is not a terminal; flags such as --color=always or the FORCE_COLOR environment variable turn it back on.

The codes

An SGR sequence is ESC, then [, then numbers separated by semicolons, then m: 31 sets red text, 1 bold, 0 resets, 38;5;n selects from the 256-colour palette and 38;2;r;g;b a true colour. The codes are defined in ECMA-48 and listed in the ANSI escape code article.

Share

Frequently asked questions

How do I strip ANSI codes in a terminal?
Pass the output through the plain-text mode here, or through a sed expression that deletes the escape character followed by [, digits and a letter. Many tools also offer --no-color or respect the NO_COLOR environment variable.
Why do I see things like [0m in my logs?
The escape character itself is invisible or was dropped, leaving the rest of the sequence. Those fragments are colour resets from a program that assumed it was writing to a terminal.
Is what I paste sent anywhere?
No. The tool runs entirely in your browser with JavaScript. Nothing you type or paste is sent to our server or stored.

Go deeper

Suggested reading

Flat illustration for the post “Rust Error Too Many Open Files and Raising the Limit”, composed around deploy.
Tooling

Rust Error Too Many Open Files and Raising the Limit

Os error 24 means the process hit its file descriptor limit. Check the limit and the live count, find the leak or the missing bound, raise the limit in systemd, Docker or code, and cap concurrency so it stays low.

4 min read

Keep planning

Similar tools