Search code examples
javascriptjquerycsscolors

Get color name by HEX or RGB


How can I get a color name using JS/JQuery, knowing the code RBG/HEX?

For example:

Colorname      RGB
black          #000000  
white          #FFFFFF
red            #FF0000
green          #008000

Solution

  • You can use Name that Color.

    Example:

    let result = ntc.name('#6195ed');
    
    let rgb_value = result[0];      // #6495ed         : RGB value of closest match
    let specific_name = result[1];  // Cornflower Blue : Color name of closest match
    let is_exact_match = result[2]; // false           : True if exact color match
    

    There is also a variation of Name that Color that includes additional parameters:

    http://www.color-blindness.com/color-name-hue-tool/js/ntc.js

    Example:

    let result = ntc.name('#6195ed');
    
    let rgb_value = result[0];      // #6495ed         : RGB value of closest match
    let specific_name = result[1];  // Cornflower Blue : Color name of closest match
    let shade_value = result[2];    // #0000ff         : RGB value of shade of closest match
    let shade_name = result[3];     // Blue            : Color name of shade of closest match
    let is_exact_match = result[4]; // false           : True if exact color match