Look at the left square first.
Give your eyes a moment on the cream field. How light or dark does the gray seem next to it? Now look at the square on the navy field. Many people see that one as lighter.
Your eyes judge a patch of gray in relation to the colors around it. Here’s a way to catch that happening, then check whether the gray itself changed.
Compare the squares ↓
Give your eyes a moment on the cream field. How light or dark does the gray seem next to it? Now look at the square on the navy field. Many people see that one as lighter.
A strip of the same gray now connects the squares. Follow it past the point where cream meets navy. Your screen is drawing one color from end to end, even if the two ends look different.
Now the two backgrounds match. Compare the squares again. Your first impression depended partly on the lightness of the area around each square. That relationship matters when you pick a wall paint, lay out a poster or choose a frame for a print.
Trace the strip from one end to the other. The gray is #88847d along its entire length.
Cut two squares from the same gray envelope. Put one on a white sheet and the other on a dark book cover in the same light. What happens when you swap the scraps?
If the apparent difference follows the background when you swap the scraps, their surroundings are doing the work. Slide the scraps together on one sheet to compare them directly.
Another question to try How do I blur the background in a photo?