which one is faster: hex color codes or color names?

后端 未结 3 1618
灰色年华
灰色年华 2020-12-11 15:28

I just wanted to know if it\'s faster to use hex color codes or the color names when I want to use it in CSS?

3条回答
  •  我在风中等你
    2020-12-11 16:12

    I'll go against popular consensus and suggest that it's possible that the color names are faster, if the look-up table returns the color value as an integer. That would mean that when using a named color the browser does not have to manually parse from a string containing hex characters to the corresponding integer, all it needs to do is an O(1) hash look-up. And that may well be slightly faster than parsing from string to integer.

    Though as others have rightly noted, in all practical terms the difference between the two will be infinitesimally small. Not something you would ever notice in practice.

提交回复
热议问题