COLOR - CMD


Overview

The COLOR command in Windows Command Prompt (CMD) is used to set the default foreground (text) and background colors of the console window. This command can enhance readability or personalize the look of the command-line interface. It is often used in scripts to denote different process stages or alert statuses visually.

Syntax

To use the COLOR command, the syntax is:

COLOR [attribute]

The attribute is a two-digit hexadecimal code where the first digit represents the background color and the second digit represents the text color.

If no attribute is provided, the command resets the color to what was set when CMD was opened.

Options/Flags

The COLOR command supports hexadecimal characters, each representing a different color:

  • 0 Black
  • 1 Blue
  • 2 Green
  • 3 Aqua
  • 4 Red
  • 5 Purple
  • 6 Yellow
  • 7 White
  • 8 Gray
  • 9 Light Blue
  • A Light Green
  • B Light Aqua
  • C Light Red
  • D Light Purple
  • E Light Yellow
  • F Bright White

Leading zero is necessary if the color attribute should change only one color (foreground or background).

Default:
If the COLOR command is run without arguments, it will revert to the default colors of the CMD window.

Examples

  • Set text color to Light Red with Black background
    COLOR 4C
    
  • Reset to default color settings
    COLOR
    
  • Set background to Green and text color to Light Aqua
    COLOR 2B
    

Common Issues

  • Invalid color codes: Users must ensure the syntax contains only two valid hexadecimal characters. If invalid codes are used, CMD will ignore the command.
  • Visibility issues: Some color combinations (e.g., blue text on a blue background) can lead to unreadable text. Always choose contrasting colors.

Integration

Script Usage

In batch files, COLOR can be used to signal different sections of the script or signify success/warning/error states:

@echo off
COLOR 2E
echo Starting processing...
REM Processing steps here
COLOR 4E
echo WARNING: Low memory detected.
REM More processing steps here
COLOR A2
echo Process completed successfully.

Combined with ECHO

Used with ECHO, COLOR can highlight specific messages:

COLOR C
echo IMPORTANT: System will restart in 5 minutes!
  • MODE: Adjusts properties of the console, including display settings.
  • TITLE: Sets the Command Prompt window title which can be visually informative along with color coding.

For more commands related to CMD customization, see Microsoft’s official CMD documentation.

This guide covers how to use the COLOR command to customize the appearance of your CMD session dynamically and visually communicates the condition or status within scripts or during routine CMD interactions.