Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@visulima/is-ansi-color-supported

visulima1.8kMIT2.2.14TypeScript support: included

Detect whether a terminal or browser supports ansi colors.

anolilab, visulima, colorize, ansi, colour, color, colors, styles, terminal, xterm, console, cli, truecolor, FORCE_COLOR, NO_COLOR, ansi-colors, style, tty, 256, detect, edge, next.js, nextjs, support, supports, capability, shell, command-line

readme

Visulima is-ansi-color-supported

Detect whether a terminal (stdout/stderr), browser or edge supports (next.js) ansi colors.


[typescript-image][typescript-url] [![npm-image]][npm-url] [![license-image]][license-url]


Daniel Bannert's open source work is supported by the community on GitHub Sponsors


Install

npm install @visulima/is-ansi-color-supported
yarn add @visulima/is-ansi-color-supported
pnpm add @visulima/is-ansi-color-supported

Usage

import { isStdoutColorSupported, isStderrColorSupported } from "@visulima/is-ansi-color-supported";

/**
 * Levels:
 * - `0` - All colors disabled.
 * - `1` - Basic 16 colors support.
 * - `2` - ANSI 256 colors support.
 * - `3` - Truecolor 16 million colors support.
 */
console.log(isStdoutColorSupported()); // 3

console.log(isStderrColorSupported()); // 3

Color support

Ansis automatically detects the supported color space:

  • TrueColor
  • ANSI 256 colors
  • ANSI 16 colors
  • black & white (no color)

There is no standard way to detect which color space is supported. The most common way to detect color support is to check the TERM and COLORTERM environment variables. CI systems can be detected by checking for the existence of the CI and other specifically environment variables. Combine that with the knowledge about which operating system the program is running on, and we have a decent enough way to detect colors.

Terminal ANSI 16
colors
ANSI 256
colors
True
Color
env.
TERM
env.
COLORTERM
Specifically ENV variables
Azure CI dumb | TF_BUILD
AGENT_NAME
GitHub CI dumb | CI
GITHUB_ACTIONS
GitTea CI dumb | CI
GITEA_ACTIONS
GitLab CI dumb | CI
GITLAB_CI
Travis CI dumb | TRAVIS
PM2
not isTTY
✅[^1] ✅[^1] ✅[^1] dumb | PM2_HOME
pm_id
JetBrains TeamCity
>=2020.1.1
| TEAMCITY_VERSION
JetBrains IDEA xterm-256color | TERMINAL_EMULATOR='JetBrains-JediTerm'
VS Code xterm-256color truecolor
Windows
Terminal
✅[^2] |
Windows
PowerShell
✅[^2] |
macOS Terminal xterm-256color |
iTerm xterm-256color truecolor
Terminal emulator Kitty xterm-kitty

[^1]: Colors supported depends on actual terminal.

[^2]: The Windows terminal supports true color since Windows 10 revision 14931 (2016-09-21).

See also:

Environment variables

To force disable or enable colored output use environment variables NO_COLOR and FORCE_COLOR.

The NO_COLOR variable should be presents with any not empty value. The value is not important, e.g., NO_COLOR=1 NO_COLOR=true disable colors. See standard description by NO_COLOR.

The FORCE_COLOR variable should be presents with one of values:\ FORCE_COLOR=0 force disable colors\ FORCE_COLOR=1 force enable colors

CLI arguments

Use arguments --no-color or --color=false to disable colors and --color to enable ones.

For example, an executable script colors.js:

#!/usr/bin/env node
import { isStdoutColorSupported } from "@visulima/is-ansi-color-supported";

console.log(isStdoutColorSupported());

Execute the script in a terminal:

$ ./colors.js                        # colored output in terminal
$ ./colors.js --no-color             # non colored output in terminal
$ ./colors.js --color=false          # non colored output in terminal

$ ./colors.js > log.txt              # output in file without ANSI codes
$ ./colors.js --color > log.txt      # output in file with ANSI codes
$ ./colors.js --color=true > log.txt # output in file with ANSI codes

Warning

The command line arguments have a higher priority than environment variable.

Info

For situations where using --color is not possible, use the environment variable FORCE_COLOR=1 (level 1), FORCE_COLOR=2 (level 2), or FORCE_COLOR=3 (level 3) to forcefully enable color, or FORCE_COLOR=0 to forcefully disable. The use of FORCE_COLOR overrides all other color support checks.

Explicit 256/Truecolor mode can be enabled using the --color=256 and --color=16m flags, respectively.

Supported Node.js Versions

Libraries in this ecosystem make the best effort to track Node.js’ release schedule. Here’s a post on why we think this is important.

Contributing

If you would like to help take a look at the list of issues and check our Contributing guild.

Note: please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

Credits

License

The visulima is-ansi-color-supported is open-sourced software licensed under the [MIT][license-url]

[typescript-url]: https://www.typescriptlang.org/ "TypeScript" "typescript" [license-image]: https://img.shields.io/npm/l/@visulima/is-ansi-color-supported?color=blueviolet&style=for-the-badge [license-url]: LICENSE.md "license" [npm-image]: https://img.shields.io/npm/v/@visulima/is-ansi-color-supported/latest.svg?style=for-the-badge&logo=npm [npm-url]: https://www.npmjs.com/package/@visulima/is-ansi-color-supported/v/latest "npm"

changelog

@visulima/is-ansi-color-supported 2.2.14 (2025-05-30)

Bug Fixes

  • is-ansi-color-supported: update dependencies (f3050bb)

Miscellaneous Chores

  • updated dev dependencies (2433ed5)

@visulima/is-ansi-color-supported 2.2.13 (2025-03-07)

Bug Fixes

  • updated @visulima/packem and other dev deps, for better bundling size (e940581)

Miscellaneous Chores

  • fixed issue with pnpm audit, changed browser path (67337cb)
  • updated dev dependencies (487a976)

@visulima/is-ansi-color-supported 2.2.12 (2025-01-25)

Bug Fixes

  • fixed wrong node version range in package.json (4ae2929)

Miscellaneous Chores

  • fixed typescript url (fe65a8c)
  • updated all dev dependencies (37fb298)

@visulima/is-ansi-color-supported 2.2.11 (2025-01-22)

Bug Fixes

  • fixed support for edge-light runtime (40e9ea3)

Miscellaneous Chores

  • updated all dev dependencies and all dependencies in the app folder (87f4ccb)

@visulima/is-ansi-color-supported 2.2.10 (2025-01-12)

Bug Fixes

  • updated @visulima/packem, and all other dev dependencies (7797a1c)

Miscellaneous Chores

  • updated dev dependencies (9de2eab)

@visulima/is-ansi-color-supported 2.2.9 (2024-12-12)

Bug Fixes

  • added missing placeholder variables into LICENSE.md file (cef32c6)
  • allow node v23 (8ca929a)
  • allowed node 23, updated dev dependencies (f99d34e)
  • create a new edge-light export to remove the process check in browser export and updated packem to v1.9.2 (c3b73c6)
  • updated packem to v1.8.2 (23f869b)

Styles

  • cs fixes (46d31e0)
  • is-ansi-color-supported: fixed order of exports (2e89785)

Miscellaneous Chores

  • updated dev dependencies (a916944)

@visulima/is-ansi-color-supported 2.2.8 (2024-10-05)

Bug Fixes

  • updated dev dependencies, updated packem to v1.0.7, fixed naming of some lint config files (c071a9c)

@visulima/is-ansi-color-supported 2.2.7 (2024-09-24)

Bug Fixes

  • update packem to v1 (05f3bc9)
  • updated esbuild from v0.23 to v0.24 (3793010)

Miscellaneous Chores

  • updated dev dependencies (05edb67)

@visulima/is-ansi-color-supported 2.2.6 (2024-09-11)

Bug Fixes

Miscellaneous Chores

  • updated dev dependencies (28b5ee5)

@visulima/is-ansi-color-supported 2.2.5 (2024-09-07)

Bug Fixes

  • fixed broken chunk splitting from packem (1aaf277)

@visulima/is-ansi-color-supported 2.2.4 (2024-09-07)

Bug Fixes

  • added types support for node10 (604583f)

Miscellaneous Chores

  • update dev dependencies (0738f98)
  • updated dev dependencies (45c2a76)

@visulima/is-ansi-color-supported 2.2.3 (2024-08-01)

Bug Fixes

  • upgraded @visulima/packem (dc0cb57)

Styles

  • cs fixes (6f727ec)
  • fixed found code style issue with eslint and prettier (114e9c9)

Miscellaneous Chores

  • changed typescript version back to 5.4.5 (55d28bb)
  • is-ansi-color-supported: remove old field in package.json (d49b48d)
  • updated dev dependencies (ac67ec1)
  • updated dev dependencies (34df456)
  • updated dev dependencies and sorted the package.json (9571572)

@visulima/is-ansi-color-supported 2.2.2 (2024-06-13)

Bug Fixes

  • is-ansi-color-supported: switched from tsup to packem (d13332f)

Styles

Miscellaneous Chores

Build System

  • fixed found audit error, updated all dev package deps, updated deps in apps and examples (4c51950)

@visulima/is-ansi-color-supported 2.2.1 (2024-06-06)

Bug Fixes

Styles

Miscellaneous Chores

  • changed semantic-release-npm to pnpm (b6d100a)
  • deps: updated dev deps (d91ac38)
  • update dev dependencies (068bdbf)
  • update dev dependencies (09c4854)
  • updated dev dependencies (a2e0504)
  • updated dev dependencies (abd319c)
  • updated dev dependencies (0767afe)
  • updated dev dependencies (d7791e3)
  • updated dev dependencies (6005345)

@visulima/is-ansi-color-supported 2.2.0 (2024-04-09)

Features

  • is-ansi-color-supported: add support for PM2 process manager (dd8bb6f)
  • is-ansi-color-support: updated readme (38ca0a0)

Bug Fixes

  • fixed CLI flags and FORCE_COLOR should precede other color support checks (d8b524e)

@visulima/is-ansi-color-supported 2.1.0 (2024-04-09)

Features

  • is-ansi-color-supported: added new const exports, added check f… (#390) (167f5b3)

@visulima/is-ansi-color-supported 2.0.2 (2024-03-27)

Bug Fixes

  • added missing os key to package.json (4ad1268)

@visulima/is-ansi-color-supported 2.0.1 (2024-03-04)

Bug Fixes

  • fixed all found type issues (eaa40d1)
  • minifyWhitespace on prod build, removed @tsconfig/* configs (410cb73)

@visulima/is-ansi-color-supported 2.0.0 (2024-02-28)

⚠ BREAKING CHANGES

  • export changed to isStderrColorSupported,isStdoutColorSupported; isColorSupported is now isStdoutColorSupported

Signed-off-by: prisis d.bannert@anolilab.de

Features

  • added support for stderr, migrated deno api to v2 (2e8ac8f)

Bug Fixes

@visulima/is-ansi-color-supported 1.2.0 (2024-02-20)

Features

@visulima/is-ansi-color-supported 1.1.0 (2024-01-31)

Features

  • added GITHUB_WORKFLOW env to the ansi color check (080ec5f)

@visulima/is-ansi-color-supported 1.0.0 (2024-01-28)

Features

  • added colorize and is-ansi-color-supported (e2d9945)

Bug Fixes

  • fixed wrong package.json (43dd507)