Is Light Color

Check if a hex color is light (good for determining text color).

Code

General
const num = parseInt(hex.replace('#', ''), 16);
const r = (num >> 16) & 255, g = (num >> 8) & 255, b = num & 255;
return (r * 0.299 + g * 0.587 + b * 0.114) > 186;

Parameters

Hex color to check

Browser·fetch() may be limited by CORS

More JavaScript Snippets