The tiniest and the fastest library for terminal output formatting with ANSI colors
picocolors is an ultra-lightweight ANSI color formatting library designed for terminal output in Node.js and browser environments. At roughly 1KB with zero dependencies, it provides the essential color and styling functions needed for CLI tools, build system logs, and developer consoles. The package prioritizes raw performance and minimal bundle impact over feature richness.
With over 111 million weekly downloads, picocolors has become the de facto standard for production tools that need reliable color output without bloat. It's been adopted by major projects like PostCSS, SVGO, Stylelint, and Browserslist, and is even vendored directly into Next.js for its build logging. This widespread adoption stems from its pragmatic design: it does one thing well without introducing transitive dependencies that could cause version conflicts or security audit noise.
The library exports a simple API with color functions (red, green, blue, etc.), background colors (bgRed, bgCyan, etc.), and text modifiers (bold, dim, italic, underline). Functions can be nested and work seamlessly with template literals. It automatically detects terminal color support and respects the NO_COLOR environment variable. The package ships with TypeScript declarations and supports both CommonJS and ESM, making it compatible with modern build toolchains and legacy Node.js versions back to v6.
For developers building CLI tools, picocolors offers the best performance-to-functionality ratio available. Its ~14x smaller size compared to Chalk and 2x speed advantage make it ideal for libraries that are installed as dependencies of dependencies, where bundle size compounds quickly. The trade-off is a deliberately minimal feature set—no theming systems, no color composition utilities, just straightforward ANSI escape code generation.
import pc from 'picocolors';
// Basic colors and styles
console.log(pc.green('✓ Build successful'));
console.log(pc.red('✗ Error: Module not found'));
console.log(pc.yellow('⚠ Warning: Deprecated API'));
// Nested formatting with template literals
const filename = 'app.js';
const time = '1.2s';
console.log(
pc.cyan(`Compiled ${pc.bold(filename)} in ${pc.dim(time)}`)
);
// Background colors and modifiers
console.log(pc.bgRed(pc.white(' FAIL ')));
console.log(pc.inverse(' PASS '));
console.log(pc.italic('Hint: Check your configuration'));
// Conditional coloring based on terminal support
function formatLog(level, message) {
if (!pc.isColorSupported) {
return `[${level}] ${message}`;
}
const colors = {
info: pc.blue,
warn: pc.yellow,
error: pc.red
};
return colors[level](`[${level.toUpperCase()}]`) + ` ${message}`;
}
console.log(formatLog('info', 'Server started on port 3000'));
console.log(formatLog('warn', 'High memory usage detected'));
console.log(formatLog('error', 'Database connection failed'));
// Custom color instance with forced enable/disable
const alwaysColored = pc.createColors(true);
console.log(alwaysColored.magenta('This is colored even if piped'));CLI tool development: Building command-line interfaces where startup time matters. Use picocolors to format help text, success/error messages, and progress indicators without adding milliseconds to tool initialization. Particularly valuable in tools invoked frequently like linters or formatters.
Build system output: Colorizing webpack, Vite, or Rollup plugin logs where the library gets bundled into the build tool itself. Every kilobyte added to build tools multiplies across millions of developer machines, making picocolors' tiny footprint critical.
Library logging: Adding colored console output to npm packages where you want to minimize the dependency footprint for downstream consumers. Since your package becomes a transitive dependency, keeping it lightweight prevents dependency tree bloat.
Server-side logging: Formatting Node.js application logs during development with color-coded log levels (info in blue, warnings in yellow, errors in red). The automatic color detection ensures logs remain clean in production CI/CD environments that don't support ANSI.
Browser developer tools: Styling console.log output in browser DevTools for debugging SPAs or during development builds. Picocolors works in browsers and adds negligible size to development bundles that get tree-shaken in production.
npm install picocolorspnpm add picocolorsbun add picocolors