ANSI colours are available by default in Windows version 1909 or newer. See below for older versions.
Specify the colour codes in a batch file by ECHOing the foreground and/or background COLOR codes (from the following table) followed by the text to be formatted, followed by the ANSI default (Esc[0m) to reset the terminal back to the default colours.
These codes are the same as those used in a Unix/Linux/VT 100 terminal though the colours may be slightly different shades.
Colour Foreground Background COLOR equivalent Default Esc[0m Black BLACK █ Esc[30m Esc[40m 0 Red DARK_RED █ Esc[31m Esc[41m 4 Green DARK_GREEN █ Esc[32m Esc[42m 2 Yellow DARK_YELLOW █ Esc[33m Esc[43m 6 Blue DARK_BLUE █ Esc[34m Esc[44m 1 Magenta DARK_MAGENTA █ Esc[35m Esc[45m 5 Cyan DARK_CYAN █ Esc[36m Esc[46m 3 Light gray DARK_WHITE █ Esc[37m Esc[47m 7 Dark gray BRIGHT_BLACK █ Esc[90m Esc[100m 8 Light red BRIGHT_RED █ Esc[91m Esc[101m C Light green BRIGHT_GREEN █ Esc[92m Esc[102m A Light yellow BRIGHT_YELLOW █ Esc[93m Esc[103m E Light blue BRIGHT_BLUE █ Esc[94m Esc[104m 9 Light magenta BRIGHT_MAGENTA █ Esc[95m Esc[105m D Light cyan BRIGHT_CYAN █ Esc[96m Esc[106m B White WHITE █ Esc[97m Esc[107m F Bold Esc[1m Underline Esc[4m No underline Esc[24m Reverse text Esc[7m Positive text (not reversed) Esc[27m The Esc character in the above table must be entered with the key combination Ctrl+[
In a text editor this may appear as ^[ or Esc[ or ¿[
Many basic text editors do not provide a method of entering an ANSI Esc character (n.b. do not confuse this with the CMD Escape character) to work around this, either enter the Esc character at the command line or use an editor like Notepad++ which allows copy and paste.
The actual colours displayed are dependent on the Terminal color scheme which can be set using ColorTool.exe The new default colour scheme is called campbell.ini. This was first introduced in Windows 10 clean-install version build 16257 (1709).
The colour swatches on this page are based on the new COLOR defaults.
ANSI colour codes do also support redirection to a text file. You may then use TYPE to display such an output file complete with colours. However if you want to easily access the raw text without any colour codes e.g. for further manipulation/sorting then avoid applying any color codes until after that has been done.
PowerShell 7.2 added a new automatic variable, $PSStyle, and changes to the PowerShell engine to support the output of ANSI-decorated text. See about_ANSI_Terminals for more.
To use ANSI colours in the Windows terminal requires setting VirtualTerminalLevel.
VirtualTerminalLevel = 1 is now set by default for the terminal and in ConPTY.
In Windows 10 versions 1511 through to 1903 this had to be enabled in the registry at:[HKEY_CURRENT_USER\Console]
"VirtualTerminalLevel"=dword:00000001Alternatively it can be enabled by calling the SetConsoleMode API with the ENABLE_VIRTUAL_TERMINAL_PROCESSING flag.
The latest W10 Console has full 24-bit colour support, this is primarily for Linux compatibility so the console properties page and the default Windows colour mappings still use just 16 colors, there is no plan to add additional console colors to the Win32 API.
To take advantage of the new colours use ColorTool.exe and install a theme, or use the VT100 sequences described here.
When the VT100 sequences are used with a version of the Windows Console that supports 24-bit colorus they will display the desired RGB color, older consoles will choose the nearest appropriate colour from the existing 16 colour table.
@Echo off
Echo ¤[91m This text will display in Red
¤[0m
In the above ¤ represents the Esc character.
A batch file to save the ESC character in a variable %ESC% (via Aacini on the Dostips forum)
@Echo Off
for /f %%a in ('echo prompt $E^| cmd') do set "ESC=%%a"
echo %ESC%[41mHello world%ESC%[%m
A batch file to display the ANSI colours: EchoANSI.CMD
Output:
“In nature, light creates the color; in the picture, color creates light.
Every color shade emanates a very characteristic light — no substitute is possible” ~ Hans Hofmann
ECHO - Display a message on screen.
TYPE - Display the contents of a text file.
How-to: 256 Colors for XTerm (Linux)
In MS-DOS ANSI support could be installed by loading ansi.sys at startup.
ConPTY - Blog post describing the Windows Pseudo Console.
Console Virtual Terminal Sequences - Full list of VT 100 codes, positioning, colors, modes, RGB (for non Windows consoles).
Dracula Theme - A dark theme for the Windows 10 Console.
WT.exe - Windows Terminal
CSS/HTML Colour codes