- 
      
 - 
        
Save eeslom/2a7ba4b16cec0acf939c7f5ba394d0f2 to your computer and use it in GitHub Desktop.  
    Check if hex color dark or light
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | const isColorDark = color => { | |
| const c = color.substring(1); // strip # | |
| const rgb = parseInt(c, 16); // convert rrggbb to decimal | |
| const r = (rgb >> 16) & 0xff; // extract red | |
| const g = (rgb >> 8) & 0xff; // extract green | |
| const b = (rgb >> 0) & 0xff; // extract blue | |
| const luma = 0.2126 * r + 0.7152 * g + 0.0722 * b; // per ITU-R BT.709 | |
| const isDark = luma < 40; | |
| return isDark; | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment