Hex colors display differently between Chrome and

2019-02-15 17:54发布

问题:

Is it possible for a hexadecimal color value to be displayed differently between browsers? While working on a site, I kept noticing a difference in a red that I was using when previewing between Chrome and Safari.

  • Chrome: Version 58.0.3029.110 (64-bit)
  • Safari: Version 10.1.1 (12603.2.4)
  • MacOS Sierra: Version 10.12.5 (16F73)
  • iMac (Retina 5K, 27-inch, Late 2014)

Code:

<!DOCTYPE html>
<html>
<head>
	<title>Color Test</title>
	<style type="text/css">
body {
	height: 200px;
	background-color: #ff3324;
}	
	</style>

</head>
<body>


</body>
</html>

Color comparison screenshot: Left: Chrome
Right: Safari

What's wrong?

回答1:

This is because Safari has access to your monitor's ICC profile, and that it will use it to provide the best correspondence in sRGB.

On mac, you can check it with the DigitalColor Meter utility you've got in you Apps > Utilities. Set it to Display in sRGB to see the colors measured. Safari will always display the correct sRGB color, while Chrome and Firefox will be off with an non standard sRGB color profile.

If you set your monitor's color profile to an standard sRGB one, then all browsers will show the correct values.

There is no setting in Safari to make it behave like others, and I didn't found a way in chrome either ; Firefox has some flags about color management, but I think it's only about images' embedded ICC profiles, not the monitor's one.

[edit],

Actually FF's flags gfx.color_management.XXXX do also apply to the rendered colors, and will provide the same behavior as Safari. But, it seems there are bugs when setting it (e.g canvas' getImageData() method will return the displayed sRGB values instead of the RGB ones that has been authored).