Home › Developer Tools › ANSI Color Code Generator

ANSI Color Code Generator

Pick a text color, background and styles such as bold or underline, see exactly how it looks in a terminal, and copy ready-to-run code for bash, Python, JavaScript (Node.js) and C. Basic 16 colors, the 256-color palette and 24-bit RGB truecolor are all supported.

Last updated:

Text color
Background
Style

Preview

Bash / shell
Python
JavaScript / Node.js
C / C++
    Advertisement
    Advertisement

    How to use the ANSI Color Code Generator

    1. Type the text you want to print in the terminal.
    2. Choose a text color: one of the 16 basic colors, a number from the 256-color palette, or any RGB color.
    3. Optionally pick a background and styles such as bold, italic or underline.
    4. Check the preview and the escape sequence, switching to a light terminal if that is what you use.
    5. Copy the code for your language and run it; keep the reset at the end so later output is not affected.

    ANSI color code reference

    ColorTextBackgroundBright textBright background
    Black304090 (gray)100
    Red314191101
    Green324292102
    Yellow334393103
    Blue344494104
    Magenta354595105
    Cyan364696106
    White374797107
    256-color38;5;n48;5;nn = 0-255
    RGB truecolor38;2;r;g;b48;2;r;g;beach 0-255
    Default3949

    Style codes

    CodeEffectTurn off with
    0Reset everything
    1Bold (some terminals also brighten the color)22
    2Dim / faint22
    3Italic23
    4Underline24
    5Blink (often disabled)25
    7Reverse foreground and background27
    8Hidden / conceal28
    9Strikethrough29

    How the 256-color palette is built

    Numbers 0-15 are the basic and bright colors from your terminal theme. Numbers 16-231 form a 6×6×6 color cube: the index is 16 + 36×r + 6×g + b, where r, g and b are 0-5 and map to the channel levels 0, 95, 135, 175, 215 and 255. Numbers 232-255 are 24 shades of gray from rgb(8, 8, 8) to rgb(238, 238, 238) in steps of 10.

    Tips

    • Only color interactive output. Check whether output goes to a terminal ([ -t 1 ] in shell, sys.stdout.isatty() in Python, process.stdout.isTTY in Node.js) and respect the NO_COLOR environment variable.
    • Do not rely on color alone. Add a word or symbol such as "error:" or ✔ so the message is clear for color-blind users and in logs.
    • Always reset. Forgetting \033[0m leaves the user's prompt colored after your program exits.

    Frequently asked questions

    What are ANSI color codes?

    ANSI escape codes are special character sequences that terminals interpret as formatting instead of text. A sequence starts with the escape character (ESC, written \033 or \x1b), followed by [ , a list of numbers separated by semicolons and the letter m, for example \033[1;31m for bold red. These SGR (Select Graphic Rendition) codes change color and style until a reset \033[0m.

    What is the difference between 16, 256 and truecolor?

    The 16 basic colors use codes 30-37 and 90-97 for text and 40-47 and 100-107 for backgrounds, and their exact shades come from the terminal theme. The 256-color mode uses 38;5;n and 48;5;n with a fixed 6x6x6 color cube and 24 grays. Truecolor uses 38;2;r;g;b and 48;2;r;g;b for any of 16.7 million colors.

    Why does my output show codes like ^[[31m or \033[31m literally?

    The escape character was not interpreted. In bash, use printf or echo -e (plain echo prints backslashes literally), or $'...' strings. In Python and C use \033 inside a normal string literal. If the output goes to a file or a pager such as less, use less -R to display colors.

    Do ANSI colors work on Windows?

    Yes in Windows Terminal, PowerShell 7 and the VS Code terminal. The legacy Windows console only processes them when virtual terminal processing is enabled; Python programs can call os.system("") once or use the colorama package to switch it on.

    How do I reset colors back to normal?

    Print \033[0m (SGR 0), which turns off all colors and styles. Individual attributes can also be switched off: 22 ends bold and dim, 23 italic, 24 underline, 27 reverse, 39 restores the default text color and 49 the default background.

    Should I use \033, \x1b or \e?

    They all produce the same escape character (decimal 27). \033 (octal) works in bash printf, Python and C; \x1b (hex) works in Python, C and JavaScript; \e works in bash and zsh but is not standard C and is not supported by Python. JavaScript string literals need \x1b or \u001b.

    Are all the tools on FreeToolCabin tested for quality and accuracy?

    Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.

    Related tools

    Bash Prompt GeneratorDrag and drop a custom PS1 prompt for bash or zsh with colors, git branch and a live preview.HEX to RGBConvert HEX colors to RGB and other formats.Color PickerPick any color and get HEX, RGB, HSL, HSV and CMYK codes, shades and a screen eyedropper.ASCII TableFull ASCII code chart 0–255 in decimal, hex, octal, binary and HTML, with search and copy.QR Code GeneratorMake QR codes for links, Wi-Fi, email and more.Barcode GeneratorCreate Code 128, EAN-13, UPC-A, EAN-8, Code 39 and ITF-14 barcodes as PNG or SVG.UUID GeneratorGenerate UUID v4 and v7 / GUIDs in bulk and copy or download them.Schema Markup Generator (JSON-LD)Create JSON-LD structured data for FAQ, Product, Article and more.Htaccess & Nginx Redirect GeneratorBuild 301 redirects for .htaccess, Nginx and Netlify or Cloudflare _redirects.Fake Data GeneratorGenerate mock data as JSON, CSV or SQL.Random String GeneratorGenerate secure random strings and tokens in bulk with any length and character set.API Key GeneratorCreate secure API keys and secrets with prefixes, checksums and SHA-256 hashes for storage.MIME Type LookupFind the MIME type for any file extension, or the extensions for a MIME type, in 400+ entries.Cron Expression GeneratorBuild crontab schedules visually, read them in plain English and see the next run times.URL Slug GeneratorTurn titles into clean, SEO-friendly URL slugs: accents, stop words, separators and bulk lines.JSON Schema GeneratorTurn sample JSON into a draft 2020-12 JSON Schema with types, required fields and formats.Gitignore GeneratorBuild a .gitignore from 50+ templates for languages, frameworks, IDEs and OS, merged and deduped.License GeneratorCreate a LICENSE file for MIT, Apache, GPL, BSD, ISC, MPL or Unlicense with your name and year.ULID GeneratorGenerate sortable ULIDs and UUID v7 in bulk, monotonic option, and decode their timestamps.Htpasswd GeneratorCreate .htpasswd entries with bcrypt, APR1-MD5 or SHA-1 for Apache and Nginx basic auth.Placeholder Image GeneratorCreate placeholder images in any size, color and text as PNG, JPG, WebP, SVG or data URI.Ads.txt GeneratorCreate or validate ads.txt and app-ads.txt files: seller lines, cert IDs and variables.Docker Run to Compose ConverterConvert docker run commands to docker-compose.yml, or a compose file back to docker run.Dockerfile GeneratorGenerate a production Dockerfile and .dockerignore for Node, Python, Go or a static nginx site.HTML Boilerplate GeneratorTick the options you need and get a clean HTML5 starter template with meta, OG tags and CSS reset.JSON to Zod SchemaInfer a Zod (or Yup) schema from sample JSON with optional, nullable and z.infer types.Linux Commands Cheat SheetSearchable Linux and bash command reference with flags explained, examples and copy buttons.LLMs.txt GeneratorBuild an llms.txt file for AI crawlers: summary and link sections, import from your sitemap.Nano ID GeneratorGenerate secure Nano IDs with custom alphabet, length and count, plus a collision calculator.Nginx Config GeneratorBuild an nginx server block: static site, SPA, reverse proxy or PHP, with SSL, gzip and redirects.OpenAPI / Swagger ViewerView OpenAPI 2/3 JSON or YAML as interactive API docs with validation and an endpoint list.package.json GeneratorFill a form and get a valid, npm-ready package.json with scripts, dependencies and checks.PKCE Code Challenge GeneratorGenerate an OAuth 2.0 PKCE code_verifier and S256 code_challenge, build auth URLs, verify pairs.README GeneratorFill in a form and get a polished README.md with badges, install, usage and license, live preview.Regex GeneratorBuild regular expressions visually from blocks or presets (email, date, phone) and test them live.Commit Message GeneratorBuild Conventional Commit messages with type, scope, body, breaking change and issue refs.Database Schema DesignerDesign tables and relationships visually, then export SQL for MySQL, PostgreSQL or SQLite.Docker Compose GeneratorBuild a docker-compose.yml with a form: services, ports, volumes, env, healthchecks and presets.FFmpeg Command GeneratorPick a task and options, get the exact ffmpeg command with every flag explained.Folder Tree GeneratorTurn a local folder or an indented list into an ASCII directory tree for your README.GitHub Actions Workflow GeneratorBuild a GitHub Actions CI workflow: triggers, matrix, caching, tests, Pages or Docker deploy.Kubernetes YAML GeneratorGenerate Deployment, Service, Ingress, ConfigMap, Secret and HPA manifests with safe defaults.Markdown TOC GeneratorGenerate a linked table of contents from Markdown headings with GitHub-style anchors.OpenAPI EditorEdit OpenAPI/Swagger YAML or JSON side by side with live API docs, validation and download.OpenAPI ValidatorValidate OpenAPI 3.0/3.1 and Swagger 2.0 specs: schema errors, broken $refs, line numbers.Pivot Table MakerBuild pivot tables from CSV or Excel by drag and drop: sum, count, average, charts, export.SQL Query BuilderBuild SELECT queries visually: joins, filters, GROUP BY, ORDER BY and LIMIT, as clean SQL.Truth Table GeneratorType a logic expression and get its full truth table, minterms and canonical DNF/CNF.TypeScript PlaygroundWrite TypeScript with live type checking, see the compiled JavaScript and run it in your browser.Article Schema GeneratorCreate Article, BlogPosting or NewsArticle JSON-LD with headline, authors, dates and images.Event Schema GeneratorCreate Event JSON-LD with dates, venue or online location, tickets, organizer and performers.Google Search Query BuilderBuild advanced Google searches with site:, filetype:, intitle:, exact phrases and date operators.HowTo Schema GeneratorCreate HowTo JSON-LD with steps, tools, supplies, total time and cost, then copy it.Htaccess GeneratorBuild an Apache .htaccess file: HTTPS, www, gzip, caching, error pages, IP blocks, hotlinks.HTML Email Template BuilderDrag and drop blocks to build a responsive, table-based HTML email with inline styles.Organization Schema GeneratorCreate Organization JSON-LD with logo, URL, contact points, address and social profiles.PIN GeneratorGenerate random 4, 6 or 8-digit PINs that avoid sequences, repeats, dates and common PINs.Product Schema GeneratorBuild Product JSON-LD with price, availability, brand, GTIN, ratings and reviews.Question Keyword GeneratorFind the questions people ask about a topic, grouped by who, what, why, how, can and more.Recipe Schema GeneratorCreate Recipe JSON-LD with ingredients, steps, prep and cook times, nutrition and ratings.Security Headers GeneratorPick HSTS, CSP, frame, referrer and permissions options and get Apache, Nginx, Netlify or Cloudflare config.SKU GeneratorBuild consistent SKUs from brand, category, size and color, then export every variant as CSV.Typography Scale GeneratorBuild a modular type scale from a base size and ratio, then copy CSS variables or a Tailwind config.WordPress Salt GeneratorGenerate fresh WordPress security keys and salts for wp-config.php, .env or Docker in one click.Apache Virtual Host GeneratorCreate an Apache VirtualHost config with SSL, redirects, reverse proxy or PHP-FPM in seconds.Changelog GeneratorTurn Conventional Commit messages into a grouped Keep a Changelog Markdown file per version.cURL Command BuilderBuild curl commands from a form: method, headers, query, JSON or form body, auth and flags.Docker Compose to KubernetesConvert docker-compose.yml into Kubernetes Deployment, Service, ConfigMap and PVC manifests.
    See all 85 Code Generators & Builders →