or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

advanced-colors.mdbackground-colors.mdbasic-colors.mdcolor-support.mdconfiguration.mdindex.mdtext-styling.md
tile.json

background-colors.mddocs/

Background Colors

Standard 16-color terminal palette for background styling. These background colors mirror the foreground color palette and provide consistent background styling across terminal emulators.

Capabilities

Standard Background Colors

The eight standard ANSI background colors available in most terminals.

/**
 * Standard background colors (all return ChalkInstance for chaining)
 */
readonly bgBlack: ChalkInstance;
readonly bgRed: ChalkInstance;
readonly bgGreen: ChalkInstance;
readonly bgYellow: ChalkInstance;
readonly bgBlue: ChalkInstance;
readonly bgMagenta: ChalkInstance;
readonly bgCyan: ChalkInstance;
readonly bgWhite: ChalkInstance;

Usage Examples:

import chalk from 'chalk';

console.log(chalk.bgBlack('Text on black background'));
console.log(chalk.bgRed('Text on red background'));
console.log(chalk.bgGreen('Text on green background'));
console.log(chalk.bgYellow('Text on yellow background'));
console.log(chalk.bgBlue('Text on blue background'));
console.log(chalk.bgMagenta('Text on magenta background'));
console.log(chalk.bgCyan('Text on cyan background'));
console.log(chalk.bgWhite('Text on white background'));

Bright Background Color Variants

Brighter/more vivid versions of the standard background colors for enhanced visual impact.

/**
 * Bright background color variants (all return ChalkInstance for chaining)
 */
readonly bgBlackBright: ChalkInstance;
readonly bgRedBright: ChalkInstance;
readonly bgGreenBright: ChalkInstance;
readonly bgYellowBright: ChalkInstance;
readonly bgBlueBright: ChalkInstance;
readonly bgMagentaBright: ChalkInstance;
readonly bgCyanBright: ChalkInstance;
readonly bgWhiteBright: ChalkInstance;

Usage Examples:

import chalk from 'chalk';

console.log(chalk.bgBlackBright('Text on bright black background'));
console.log(chalk.bgRedBright('Text on bright red background'));
console.log(chalk.bgGreenBright('Text on bright green background'));
console.log(chalk.bgYellowBright('Text on bright yellow background'));
console.log(chalk.bgBlueBright('Text on bright blue background'));
console.log(chalk.bgMagentaBright('Text on bright magenta background'));
console.log(chalk.bgCyanBright('Text on bright cyan background'));
console.log(chalk.bgWhiteBright('Text on bright white background'));

Gray/Grey Background Aliases

Convenient aliases for bgBlackBright that provide more intuitive naming for gray backgrounds.

/**
 * Aliases for bgBlackBright providing intuitive gray background naming
 */
readonly bgGray: ChalkInstance;  // Alias for bgBlackBright
readonly bgGrey: ChalkInstance;  // Alias for bgBlackBright

Usage Examples:

import chalk from 'chalk';

console.log(chalk.bgGray('Text on gray background (American spelling)'));
console.log(chalk.bgGrey('Text on grey background (British spelling)'));

// These are equivalent to:
console.log(chalk.bgBlackBright('Same as bgGray/bgGrey'));

Background Color Combinations

Background colors work seamlessly with foreground colors and text modifiers:

import chalk from 'chalk';

// Background with contrasting foreground colors
console.log(chalk.white.bgBlack('White text on black background'));
console.log(chalk.black.bgWhite('Black text on white background'));
console.log(chalk.yellow.bgBlue('Yellow text on blue background'));
console.log(chalk.red.bgGreen('Red text on green background'));

// Background colors with modifiers
console.log(chalk.bold.bgRed('Bold text on red background'));
console.log(chalk.italic.bgYellow('Italic text on yellow background'));
console.log(chalk.underline.bgCyan('Underlined text on cyan background'));

// Complex combinations
console.log(chalk.white.bold.bgBlue('White bold text on blue background'));
console.log(chalk.red.italic.bgYellow('Red italic text on yellow background'));

Practical Usage Patterns

Common patterns for using background colors in applications:

import chalk from 'chalk';

// Status badges/labels
const statusBadges = {
  success: chalk.black.bgGreen,
  warning: chalk.black.bgYellow,
  error: chalk.white.bgRed,
  info: chalk.white.bgBlue,
  pending: chalk.black.bgGray
};

console.log(statusBadges.success(' SUCCESS '));
console.log(statusBadges.warning(' WARNING '));
console.log(statusBadges.error(' ERROR '));
console.log(statusBadges.info(' INFO '));
console.log(statusBadges.pending(' PENDING '));

// Highlighting and emphasis
const highlighter = {
  important: chalk.black.bgYellowBright,
  critical: chalk.white.bgRedBright,
  note: chalk.black.bgCyanBright
};

console.log(highlighter.important(' IMPORTANT: Read this carefully '));
console.log(highlighter.critical(' CRITICAL: Immediate action required '));
console.log(highlighter.note(' NOTE: Additional information '));

// Progress indicators with backgrounds
function createProgressBar(percentage, total = 20) {
  const filled = Math.floor((percentage / 100) * total);
  const empty = total - filled;
  
  const filledBar = chalk.bgGreen(' '.repeat(filled));
  const emptyBar = chalk.bgGray(' '.repeat(empty));
  
  return `[${filledBar}${emptyBar}] ${percentage}%`;
}

console.log(createProgressBar(75));
console.log(createProgressBar(33));

Color Contrast Guidelines

For optimal readability, consider these high-contrast combinations:

import chalk from 'chalk';

// High contrast combinations (recommended)
const highContrast = [
  chalk.white.bgBlack('White on black'),
  chalk.black.bgWhite('Black on white'),
  chalk.yellow.bgBlack('Yellow on black'),
  chalk.black.bgYellow('Black on yellow'),
  chalk.cyan.bgBlack('Cyan on black'),
  chalk.black.bgCyan('Black on cyan'),
  chalk.red.bgWhite('Red on white'),
  chalk.blue.bgWhite('Blue on white')
];

highContrast.forEach(combo => console.log(combo));

// Lower contrast (use with caution)
const lowerContrast = [
  chalk.red.bgRed('Red on red (poor contrast)'),
  chalk.blue.bgBlue('Blue on blue (poor contrast)'),
  chalk.gray.bgGray('Gray on gray (poor contrast)')
];

console.log('\nLower contrast examples (harder to read):');
lowerContrast.forEach(combo => console.log(combo));

Background Color Name Arrays

For programmatic background color handling and validation:

import { backgroundColorNames } from 'chalk';

console.log('Available background colors:', backgroundColorNames);
// Outputs: ['bgBlack', 'bgRed', 'bgGreen', 'bgYellow', 'bgBlue', 'bgMagenta', 'bgCyan', 'bgWhite', 'bgBlackBright', ...]

// Validation example
function isValidBackgroundColor(colorName) {
  return backgroundColorNames.includes(colorName);
}

console.log(isValidBackgroundColor('bgRed'));    // true
console.log(isValidBackgroundColor('bgPurple')); // false