RGB-to-Hex Conversion

JavaScript FAQ | JavaScript Colors FAQ  

Question: How do I convert RGB values of a color to a hexadecimal string?

Answer: The RGB-to-hexadecimal converter algorithm is simple: make sure that your R, G, B (red, green, blue) values are in the range 0...255, convert R, G, B to hex strings, and then concatenate the three hex strings together. Convert RGB to Hex color values here:

      R: G: B:  

Source code Source code | See also Hex-to-RGB | RGB-to-CMYK | RGB-to-HSV | Color names

RGB/hex codes for named colors supported in most browsers are listed below:

See also:
• JavaScript Colors FAQ
• Hex to RGB color converter
• Hex to CMYK color converter
• RGB to CMYK color converter  
• RGB to HSV color converter
• Changing the page background color
• Changing the color of HTML elements
• Predefined color names (alphabetical list)
• Applying another stylesheet to my page
• Changing the mouse cursor style

Copyright © 1999-2012, JavaScripter.net.