---
title: Installation
product: amazing-cli
doc_type: guide
version: main
source: git2docs (code-derived, validation-filtered)
canonical: https://git2docs.com/wabam/docs/amazing-cli/chalk/installation
---

# Installation

_Installing via package manager (npm, pip, cargo, maven)_

## Overview

This page walks you through installing Chalk and importing it into your Node.js project or browser bundle. Chalk is an ESM-only library — it ships a single ES module entry point with no runtime dependencies, so your dependency graph stays clean. After installation you will have access to the default `chalk` instance and the `Chalk` constructor for creating isolated instances with custom color levels.

## Prerequisites

Before you begin, make sure your environment meets the following requirements:

- **Node.js ≥ 22** — Chalk's `package.json` declares `>=22`. CI is verified against Node 22 and Node 26; other versions are not tested.
- **ESM-compatible project** — Chalk ships no CommonJS build. Your project must be able to use ES module `import` syntax. The simplest way to enable this is to add `"type": "module"` to your `package.json`, or use the `.mjs` file extension.
- **A package manager** — npm, pnpm, or yarn. Examples below use npm; substitute your preferred tool.

## Installation

Chalk requires **Node.js ≥ 22** and an ESM-compatible runtime or bundler.

1. **Install the package** using your preferred package manager:

   ```sh
   # npm
   npm install chalk
   ```

   ```sh
   # pnpm
   pnpm add chalk
   ```

   ```sh
   # yarn
   yarn add chalk
   ```

2. **Verify your project is set to ESM.** Because Chalk is ESM-only, your project must either use `"type": "module"` in `package.json`, or import Chalk from a `.mjs` file:

   ```json
   {
     "type": "module"
   }
   ```

3. **Import Chalk** in your source file:

   ```js
   import chalk from 'chalk';
   ```

   That's all — Chalk automatically detects your terminal's color capability (none, 16-color, 256-color, or Truecolor) at import time.

> **Node.js ≥ 22.12 and CommonJS:** On Node.js ≥ 22.12, `require('chalk')` succeeds and returns the ES module namespace. Access the default export via `.default`:
>
> ```js
> // Node.js ≥22.12 only
> const chalk = require('chalk').default;
> ```
>
> On Node.js 22.0–22.11, `require('chalk')` throws `ERR_REQUIRE_ESM`. Use a dynamic `import()` or upgrade to 22.12+.

## Examples

### Apply a single color

```js
import chalk from 'chalk';

console.log(chalk.blue('Hello world!'));
```

---

### Combine styled and unstyled text

```js
import chalk from 'chalk';

console.log(chalk.blue('Hello') + ' World' + chalk.red('!'));
```

---

### Chain multiple styles

```js
import chalk from 'chalk';

console.log(chalk.blue.bgRed.bold('Hello world!'));
```

---

### Pass multiple arguments (joined with spaces)

```js
import chalk from 'chalk';

console.log(chalk.blue('Hello', 'World!', 'Foo', 'bar', 'biz', 'baz'));
```

---

### Nest styles

```js
import chalk from 'chalk';

console.log(
  chalk.green(
    'I am a green line ' +
    chalk.blue.underline.bold('with a blue substring') +
    ' that becomes green again!'
  )
);
```

---

### Use Truecolor: `hex` and `rgb`

```js
import chalk from 'chalk';

console.log(chalk.hex('#DEADED').bold('Bold gray!'));
console.log(chalk.rgb(123, 45, 67).underline('Underlined reddish color'));
```

---

### Background and underline color variants

```js
import chalk from 'chalk';

console.log(chalk.bgHex('#DEADED').underline('Hello, world!'));
console.log(chalk.bgRgb(15, 100, 204).inverse('Hello!'));
console.log(chalk.underlineHex('#DEADED').underlineCurly('Hello, world!'));
```

---

### Define reusable theme variables

```js
import chalk from 'chalk';

const error = chalk.bold.red;
const warning = chalk.hex('#FFA500'); // Orange

console.log(error('Error!'));
console.log(warning('Warning!'));
```

---

### Create an isolated instance with a fixed color level

```js
import { Chalk } from 'chalk';

const customChalk = new Chalk({ level: 0 });

console.log(customChalk.red('This text has no color codes'));
```

---

### Use `%s` substitution with chalk

```js
import chalk from 'chalk';

const name = 'Sindre';
console.log(chalk.green('Hello %s'), name);
// => 'Hello Sindre'
```

---

### Inspect detected color support

```js
import { supportsColor, supportsColorStderr } from 'chalk';

if (supportsColor) {
  console.log(`Stdout supports color at level ${supportsColor.level}`);
} else {
  console.log('Stdout does not support color');
}
```

---

### Validate available style names

```js
import { modifierNames, foregroundColorNames } from 'chalk';

console.log(modifierNames.includes('bold'));
// => true

console.log(foregroundColorNames.includes('pink'));
// => false
```

---

### CommonJS interop on Node.js ≥ 22.12

```js
// Works only on Node.js >=22.12
const chalk = require('chalk').default;

console.log(chalk.green('Hello from CJS!'));
```
