Color cmd command
Color is an inbuilt command found inside the Windows Command Processor (cmd.exe), that is used for changing the colors for the console’s foreground and background. By default, the console has white foreground color and black background color (07 color code). The command is generally used either to personalize the aesthetics of the console window, or the make the colors more appropriate for Dim or Dark Displays (ex. TN panels). In this article, we will learn about the color command and will also take a look at the various uses it offers.
Description of the Command :
Type the command – color /? in the Command Prompt.
Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.
It sets the default console foreground and background colors.
COLOR [attr] attr - Specifies the color attribute of console output.
Color attributes are specified by two hex digits –
- First corresponds to the background.
- Second corresponds to the foreground.
Using the Command :
The command takes in input 2 hexadecimal digits (2nd digit optional) where the first digit corresponds to the background color and the second digit corresponds to the foreground color.
If the first digit is only provided, then only the foreground color changes. Each digit can have any of the values in hexadecimal codepoint (0 – f) where each one corresponds to a unique color. The digit to color correspondence is as follows –
0 = Black 8 = Gray 1 = Blue 9 = Light Blue 2 = Green A = Light Green 3 = Aqua B = Light Aqua 4 = Red C = Light Red 5 = Purple D = Light Purple 6 = Yellow E = Light Yellow 7 = White F = Bright White
It will produce bright White on Dark Blue. Any combination of the above set of digits could be used, except for the special case in which the foreground and the background color is the same (Ex. color FF or color 33). In that case no color change occurs, and the value of %ERRORLEVEL% changes to 1. If the command is executed without providing any parameters, then the command will restore the color to which cmd.exe initially started as.
- Changing Only The Foreground Color :
(Hex_digit) is a digit (or character) within the hexadecimal range, i.e. it should belong in the range 0-F.
We will change the foreground color to Yellow (6).
It is clear from the above images that after executing the command Color 6, the color of the foreground changes from white to yellow.
- Changing the Color of Background And Foreground :
For changing the color of the foreground and the background of the console window, the color attributes are specified by 2 of the previously mentioned hex digits.
Back_Hex_digit and Fore_hex_digit are hexadecimal digits used to determine the color of the background and foreground respectively. In the following example, we will change the background color to grey (7) and foreground color to light green (a).