
chalk
A JavaScript library that adds colors and text styles to terminal output.
- Stars
- 23.3k
- Forks
- 2.2k
- Licence
- MIT
- Language
- JavaScript
- Last update
- 14 days ago
- Type
- Library
What it is
Chalk is a JavaScript library for styling text printed to the terminal, such as making words red, bold, or underlined. You chain style names like chalk.blue.bold('text') and it outputs the matching terminal color codes. It detects whether the terminal supports color and downgrades colors when it does not.
- Color error, warning, and success messages in a command-line tool
- Show CPU, RAM, or disk percentages in different colors in a status printout
- Define reusable themes such as an error style or a warning style
- Use RGB or hex colors in terminals that support truecolor
Great for
- Node.js developers building command-line tools that print colored output
- Developers who want readable, color-coded logs or status messages in a terminal
- Projects that need 256 or truecolor output and automatic fallback to simpler colors
- Developers who already use Chalk 4 or 5 and want to see the current API
Not ideal for
- Projects using TypeScript or build tools that cannot handle ESM: the README says Chalk 5 is ESM and suggests Chalk 4 in that case
- Projects that need the smallest possible footprint: the README points to yoctocolors as a smaller alternative
- People who need colored output in a web browser rather than a terminal
How to get it
- 1
Install with a package manager
You'll need: Node.js
Install Chalk from npm
npm install chalk - 2
Run it
- Run npm install chalk in your project folder.
- Create a file that imports chalk with import chalk from 'chalk'.
- Add console.log(chalk.blue('Hello world!')).
- Run the file with Node.js and check that the text prints in blue in your terminal.
- 3
Get the most out of it
- Use chained styles like chalk.blue.bgRed.bold to combine colors and modifiers.
- Save reusable styles as variables, such as const error = chalk.bold.red, to build a simple theme.
- Use chalkStderr for messages written to stderr so color detection matches that stream.
- Use the FORCE_COLOR environment variable or the --color and --no-color flags to control color output.
- Create a new Chalk instance with a set level when a reusable module needs its own color setting.
Downloads
Strengths
- Simple chainable API that combines styles and supports nesting
- No dependencies, according to the README highlights
- Detects color support automatically and respects flags and environment variables like FORCE_COLOR
Trade-offs
- Chalk 5 is ESM-only, which can cause friction with some TypeScript or build setups
- Several styles such as italic, underline variants, and strikethrough are marked as not widely supported by terminals
- Level overrides apply globally to all Chalk consumers unless you create a new instance
How it compares
| Project | Stars | Type | Level | Updated | Best for |
|---|---|---|---|---|---|
| chalk (this) | 23.3k | Library | beginner | 14 days ago | Node.js developers building command-line tools that print colored output |
| xterm.js | 21.3k | Library | intermediate | 7 days ago | Developers building a browser-based IDE or cloud workspace that needs an integrated terminal |
| upterm | 19k | App | intermediate | 7.5 years ago | Developers who want to try an Electron-based terminal with autocompletion |
| Terminal.Gui | 11.3k | Library | intermediate | 6 days ago | C# / .NET developers building terminal tools with forms, tables or menus |
| terminal | 105k | App | beginner | 6 days ago | Windows users who work in the command line every day and want tabs and rich text |
| hyper | 44.8k | App | beginner | 3 months ago | Developers who want a terminal they can customize with extensions or themes |
Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.