Skip to content
← Back to Community
How do I change the color of the console in c++?
Profile icon
cancrusher

I already have the color of the text in the console down but what about the background color of the console. I'm using c++ btw.

Voters
Profile icon
2025BrigidiTomm
Profile icon
cancrusher
Comments
hotnewtop
Profile icon
DynamicSquid

Check this page to get a complete list of colours.

For example, the table show the background colour red being \033]41m, and the background colour of yellow being \033[43m.

You can use it like this:

const char* BG_RED = "\033[41m"; cout << BG_RED << "Hello!";

There's also 256 bit colours, which ae described in that same page.

Hope this helps :)

Profile icon
Coder100

It is the same...?

if you mean entire terminal background, it would be much harder than just highlighted text, as this code demonstrates:

#ifndef reset #define color_reset "\x1b[0m" #define color_bold "\x1b[1m" #define color_italic "\x1b[3m" #define color_underline "\x1b[4m" #define color_inverse "\x1b[7m" #define color_black "\x1b[30m" #define color_red "\x1b[31m" #define color_green "\x1b[32m" #define color_yellow "\x1b[33m" #define color_blue "\x1b[34m" #define color_magenta "\x1b[35m" #define color_cyan "\x1b[36m" #define color_white "\x1b[37m" #define color_gray "\x1b[90m" #define color_bright_red "\x1b[91m" #define color_bright_green "\x1b[92m" #define color_bright_yellow "\x1b[93m" #define color_bright_blue "\x1b[94m" #define color_bright_magenta "\x1b[95m" #define color_bright_cyan "\x1b[96m" #define color_bright_white "\x1b[97m" #define color_bg_black "\x1b[40m" #define color_bg_red "\x1b[41m" #define color_bg_green "\x1b[42m" #define color_bg_yellow "\x1b[43m" #define color_bg_blue "\x1b[44m" #define color_bg_magenta "\x1b[45m" #define color_bg_cyan "\x1b[46m" #define color_bg_white "\x1b[47m" #define color_bg_gray "\x1b[100m" #define color_bg_bright_red "\x1b[101m" #define color_bg_bright_green "\x1b[102m" #define color_bg_bright_yellow "\x1b[103m" #define color_bg_bright_blue "\x1b[104m" #define color_bg_bright_magenta "\x1b[105m" #define color_bg_bright_cyan "\x1b[106m" #define color_bg_bright_white "\x1b[107m" #endif std::cout << color_red << "red text" << color_reset << " normal text";
Profile icon
[deleted]

You mean the console where the printed text is? I don't think you can change that. If you aren't talking about that 'console', then I'm not sure