API Reference
Chalk
Terminal string styling for Node.js with chainable colors, background, and modifier support.
Official Documentation ↗CompatibilityThis documentation covers version
v5.3. Check the official docs for the latest API surface.Installation
npm
npm install chalkpnpm
pnpm add chalkyarn
yarn add chalkMethods
No methods match this filter.
Chalk is a terminal string styling library for Node.js. It provides a chainable, composable API for applying colors, background colors, and modifiers to strings with automatic color-support detection.
Key Features
- Chainable API: Compose styles like chalk.red.bold.underline
- Template literals: Tagged templates with inline style tags
- 256 and TrueColor: hex and rgb color support
- Auto-detection: Disables colors when not a TTY
- Nested styles: Correctly reset styles on nested calls
Security notes
Quoted verbatim from the official documentation; this is not a complete threat model. 来源:https://cdn.jsdelivr.net/gh/chalk/chalk@latest/readme.md · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:48:43.712Z.
- For example, Chalk configured to run at level 1 (basic color support) will downsample an RGB value of #FF0000 (red) to 91 (ANSI escape for bright red). (https://cdn.jsdelivr.net/gh/chalk/chalk@latest/readme.md)
- Smaller packages might seem appealing now, but there’s no guarantee they will be around for the long term, or that they won’t become malicious over time. (https://cdn.jsdelivr.net/gh/chalk/chalk@latest/readme.md)
FAQ
- How does Chalk detect color support?
- Chalk inspects the TTY and environment flags like NO_COLOR, FORCE_COLOR, and CI to choose a level automatically. You can override with FORCE_COLOR=1 or by setting chalk.level and creating a new Instance.
- Is Chalk safe to use in production logs?
- Chalk adds ANSI escape codes that are fine for terminals but corrupt piped or file output. Chalk auto-disables colors when output is not a TTY, and you can force level 0 for structured logs.
- Why use Chalk over template strings with ANSI codes?
- Chalk handles color support detection, nested styles, and platform differences, and produces clean, readable code. Hand-writing ANSI codes is error-prone and does not degrade when colors are unsupported.
Report a problem with this API docOpens a pre-filled issue on GitHub.