Color Conversions

RGB to Hex

The function RGBtoHex(r,g,b) converts the given RGB color to Hex color form.
It returns a string with the Hex color value.

                
    RGBtoHex(r,g,b);

    RGBtoHex(255,0,0);     // returns "#ff0000"
            

Parameters

r Number [0-255] : Red value of the color
g Number [0-255] : Green value of the color
b Number [0-255] : Blue value of the color

RGB( , , )

Hex to RGB

The function HexToRGB(hex) converts the given Hex color to RGB color form.
It returns an object with the properties r, g, b.

                
    HexToRGB(hex);

    HexToRGB("#ff0000");   // returns {r: 255, g: 0, b: 0}
            

Parameters

hex String : Hex color value


RGB to HSL

The function RGBtoHSL(r,g,b) converts the given RGB color to HSL color form.
It returns an object with the properties h, s, l.

                
    RGBtoHSL(r,g,b);

    RGBtoHSL(255,0,0);     // returns {h: 0, s: 100%, l: 50%}
            

Parameters

r Number [0-255] : Red value of the color
g Number [0-255] : Green value of the color
b Number [0-255] : Blue value of the color

RGB( , , )

HSL to RGB

The function HSLtoRGB(h,s,l) converts the given HSL color to RGB color form.
It returns an object with the properties r, g, b.

                
    HSLtoRGB(h,s,l);

    HSLtoRGB(0,100%,50%);   // returns {r: 255, g: 0, b: 0}
            

Parameters

h Number [0-360] : Hue value of the color
s Number [0-100] : Saturation value of the color
Enter only the number, and not the percentage sign.
l Number [0-100] : Lightness value of the color
Enter only the number, and not the percentage sign.

HSL( , %, % )

HSL to Hex

The function HSLtoHex( h, s, l ) converts the given HSL color to Hex color form.
It returns a string with the Hex color value.

                
    HSLtoHex(h,s,l);

    HSLtoHex(188,100,60);      // returns '#33e3ff'
    

Parameters

h Number [0-360] : Hue value of the color
s Number [0-100] : Saturation value of the color
Enter only the number, and not the percentage sign.
l Number [0-100] : Lightness value of the color
Enter only the number, and not the percentage sign.

HSL( , %, % )

Hex to HSL

The function HexToHSL(hex) converts the given Hex color to HSL color form.
It returns an object with the properties h, s, l.

                
    HexToHSL(hex);

    HexToHSL('#33e3ff');      // returns {h: 188, s: 100, l: 60}
            

Parameters

hex String : Hex color value