Hexadecimal colors consist of six hexadecimal digits. The first two digits indicate red, the second green, and the last two blue. Within hues, 00 is the lack of color, and FF is the highest value for the color. Thus, # FF0000 will be bright red, without green or blue, and # 00CCFF will be very blue and slightly green, without red.
The color examples you give actually have a different composition of red, green, and blue. # 66CC00 is mostly green with red, and # 99FFCC is mostly green with blue and red.
You must break your colors down into your red, green, and blue components before converting them to decimal, averaging two, and then converting back:
# 66 CC 00 β 102 204 0
# 99 FF CC β 153 255 204
Average between two: 128 230 102 : # 80E666
After finding the intermediate color, you can approach the nearest web safe color: # 99FF66
The converter between hexadecimal and decimal for this can be found here .
Here is a PHP script that does what you need. Here is a JavaScript script based on the method described above (associated hex with decimal conversion in JS ):
color1 = "#66CC00"; color2 = "#99FFCC"; r1 = parseInt(color1.substring(1,3), 16); g1 = parseInt(color1.substring(3,5), 16); b1 = parseInt(color1.substring(5,7), 16); r2 = parseInt(color2.substring(1,3), 16); g2 = parseInt(color2.substring(3,5), 16); b2 = parseInt(color2.substring(5,7), 16); r3 = (Math.round((r1 + r2)/2)).toString(16); g3 = (Math.round((g1 + g2)/2)).toString(16); b3 = (Math.round((b1 + b2)/2)).toString(16); color3 = "#" + r3 + g3 + b3;