> Terminal string styling done right
[](https://codecov.io/gh/chalk/chalk)
[](https://www.npmjs.com/package/chalk?activeTab=dependents)
[](https://www.npmjs.com/package/chalk)

## Info
- [Why not switch to a smaller coloring package?](https://github.com/chalk/chalk?tab=readme-ov-file#why-not-switch-to-a-smaller-coloring-package)
- See [yoctocolors](https://github.com/sindresorhus/yoctocolors) for a smaller alternative
## Highlights
- Expressive API
- Highly performant
- No dependencies
- Ability to nest styles
- [256/Truecolor color support](#256-and-truecolor-color-support)
- [Themes](#themes) for consistent styling
- [Gradients](#gradients) for smooth color transitions
- Auto-detects color support
- Doesn't extend `String.prototype`
- Clean and focused
- Actively maintained
- [Used by ~115,000 packages](https://www.npmjs.com/browse/depended/chalk) as of July 4, 2024
## Install
```sh
npm install chalk
```
**IMPORTANT:** Chalk 5 is ESM. If you want to use Chalk with TypeScript or a build tool, you will probably want to use Chalk 4 for now. [Read more.](https://github.com/chalk/chalk/releases/tag/v5.0.0)
## Usage
```js
import chalk from 'chalk';
console.log(chalk.blue('Hello world!'));
```
Chalk comes with an easy to use composable API where you just chain and nest the styles you want.
```js
import chalk from 'chalk';
const log = console.log;
// Combine styled and normal strings
log(chalk.blue('Hello') + ' World' + chalk.red('!'));
// Compose multiple styles using the chainable API
log(chalk.blue.bgRed.bold('Hello world!'));
// Pass in multiple arguments
log(chalk.blue('Hello', 'World!', 'Foo', 'bar', 'biz', 'baz'));
// Nest styles
log(chalk.red('Hello', chalk.underline.bgBlue('world') + '!'));
// Nest styles of the same type even (color, underline, background)
log(chalk.green(
'I am a green line ' +
chalk.blue.underline.bold('with a blue substring') +
' that becomes green again!'
));
// ES2015 template literal
log(`
CPU: ${chalk.red('90%')}
RAM: ${chalk.green('40%')}
DISK: ${chalk.yellow('70%')}
`);
// Use RGB colors in terminal emulators that support it.
log(chalk.rgb(123, 45, 67).underline('Underlined reddish color'));
log(chalk.hex('#DEADED').bold('Bold gray!'));
```
Take advantage of console.log [string substitution](https://nodejs.org/docs/latest/api/console.html#console_console_log_data_args):
```js
import chalk from 'chalk';
const name = 'Sindre';
console.log(chalk.green('Hello %s'), name);
//=> 'Hello Sindre'
```
## Themes
Define a theme with multiple styles for consistent coloring:
```js
import chalk from 'chalk';
const themedChalk = chalk.theme({
error: chalk.bold.red,
success: chalk.green,
warning: chalk.hex('#FFA500'), // Orange
info: chalk.blue,
title: chalk.cyan.bold.underline,
});
console.log(themedChalk.error('Error!'));
console.log(themedChalk.success('Success!'));
console.log(themedChalk.warning('Warning!'));
console.log(themedChalk.info('Info'));
console.log(themedChalk.title('Title'));
```
Themes work with all Chalk features including gradients and chaining:
```js
const themedChalk = chalk.theme({
rainbow: chalk.gradient('#ff0000', '#00ff00', '#0000ff'),
important: chalk.red.bold.underline,
});
console.log(themedChalk.rainbow('Rainbow text'));
console.log(themedChalk.important.bgWhite('Important message'));
```
## API
### chalk.`