Can’t apply brightness to terminal’s background color

I have a problem with colors in my terminal emulator. I am using LXTerminal as my terminal emulator and LXDE as my desktop environment.

The following command is supposed to print red text on grey background:

printf "n33[1;31;40m"hello"33[00mnn"

but that does not work. The grey background is missing (red text is OK). On my older machine (Gnome/Gnome Terminal) everything works fine

I have tried installing several other terminal emulators, but the problem persists. I am not even sure whether this issue is related to terminal emulator, or something else. In Console (CTRL+ALT+F1) the background grey color does not work on either machine)

This problem is limited to grey background only. All other colors work OK, for instance the following prints red text on green background.

printf "n33[1;31;42m"hello"33[00mnn"

I would appreciate any help. I don’t even know where to start troubleshooting.


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

There are eight standard ANSI colors, supported by every terminal emulator. Most terminal emulators also have eight bright variants of the standard ANSI colors.

However, the actual color values that the escape codes map to aren’t standardized, and in fact they often slightly vary among terminal emulators. So if you do printf "e[31;47mTestn" to print red text on a white background, the actual hues of red and white you get may be different depending on the terminal emulator you use.

So that partly explains the problem: color values aren’t standard, and LXTerminal may have different defaults for its color palette that you’re not used to. If you look around in the settings, usually you can configure the color scheme to be whatever you like.

The other problem you face is that what the bold attribute actually does isn’t standardized either. There are three possibilities: it can make the font bold, it can make the foreground color brighter, or it can both make the foreground color brighter and make the font bold.

Again, the default behavior here varies among terminal emulators, and you can usually change it if can you find the right setting. Grep for something mentioning ‘bold’ or ‘bright’.

If you want to use a bright color, then you can use the so-called aixterm color escape codes instead of bold. These aren’t standard, but they’re supported in every modern terminal emulator I know of. Unlike bold, they always use bright colors, plus they can be used to display bright background colors.

So for example, if you wanted to print bright red text on a bright white background, you would do this: printf "e[91;107mTestn".

For reference, here’s a table of all the color escape codes:

|    ANSI |    ANSI |    ANSI    |                | Aixterm | Aixterm 
|   Color | FG Code | BG Code    | Bright Color   | FG Code | BG Code 
+---------+---------+--------    +----------------+---------+-------- 
|   Black |      30 |      40    |   Bright Black |      90 |     100 
|     Red |      31 |      41    |     Bright Red |      91 |     101 
|   Green |      32 |      42    |   Bright Green |      92 |     102 
|  Yellow |      33 |      43    |  Bright Yellow |      93 |     103 
|    Blue |      34 |      44    |    Bright Blue |      94 |     104 
| Magenta |      35 |      45    | Bright Magenta |      95 |     105 
|    Cyan |      36 |      46    |    Bright Cyan |      96 |     106 
|   White |      37 |      47    |   Bright White |      97 |     107

Method 2

The 1 attribute at the beginning of 1;31;40 turns on “bold” (aka. “bright”) mode, but some terminals only apply this to the foreground color. I have no idea for what reason (and changing the $TERM variable makes no difference), since they do support 16 colors in the foreground.1 0 (from 40: 4 = background, 0 = the color) is actually black, but “bright black” is gray. Here’s two solutions:

  • Color 7 (white) will probably turn out to be gray, not white (for true white, you need “bright white”, meaning the background you actually can’t have is white).
  • You should be able use gnome terminal in LXDE if you want. Just install it and start with gnome-terminal (I believe that’s its command name). Then you’ll have to configure whatever launchers to use that instead of the lx-terminal.

1 Here’s my guess: Notice that setting bold applies brightness to the foreground color and adds a bold emphasis. Hence, you can’t use a bright foreground color without also applying bold. Presumably back when monochrome terminals were common, just plain setting bold for emphasis, eg: \033[1mBlah blah\033[0m was common — and in fact this will still work, but it will also make your foreground color bright. If we considered it undesirable for this to also brighten the background (because it is just supposed to be bold), then we’d make sure the implementation didn’t do that. Oh well.

Method 3

Here’s a trick you can use with some terminal emulators. It will give you bright background colours by using the reverse-video attribute (7) to select a bright foreground colour, and then swap it with the background colour.

echo -e "e[1;32;7mText on a bright green background"

The catch is that although you can now have 16 background colours, the limitation of 8 colours now applies to the foreground/text instead. And to further confuse matters, while the reverse-video attribute is active, you have to set the text colour by using the attribute codes for background colours!

Method 4

With 47=background white instead of 40=background black you get the non-bold white as background.

]# printf "33[0;30;47m"hello"33[00mn"
hello (black on grey)
]# printf "33[1;30;47m"hello"33[00mn"
hello (darkgrey on grey)
]# printf "33[1;37;47m"hello"33[00mn"
hello (white on grey)
]# printf "33[0;37;47m"hello"33[00mn"
hello (INVISIBLE grey on grey)

Bold black results in dark grey, by default. Normal white is actually gray, because bold white is white.

This loop prints two columns with all color-on-black and white-on-color combinations.

for ((i=30; i<=47; i++))
    echo -en  "e[${i}mHelloe[0m";
    echo -e "e[1;${i}mHelloe[0m";

It starts with invisible black and darkgrey-on-black, but the other 17 lines look nice and it shows the whole console color palette.

(38 and 39 should be left out, but for simplicity I just run from 30 to 47)

Acceptd A. mentions eight colors and lack of standards.

The six colors 31-36 (red to cyan) are well defined. Black (30) and White (37) also, but their bold variants less, especially as background (40 and 47).

I just notice: in xterm the normal white text is visible on grey background, but in linux console not. (last line, with i=47) (until 30 min ago the script stopped at 46, because I wanted no unreadable variants)

In both places, when mouse-selected, it adapts cleverly and stays readable when reversed.

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x