Alex Rivera | Logout

Programmatically darken a Hex colour

Asked 2009-11-24T00:53:11.487
42

What's the easiest way to programmatically darken a hex colour?

Edit
Report

2 Answers

13

Well, I don't have any pseudocode for you, but a tip. If you want to darken a color and maintain its hue, you should convert that hex to HSB (hue, saturation, brightness) rather than RGB. This way, you can adjust the brightness and it will still look like the same color without hue shifting. You can then convert that HSB back to hex.

answered 2009-11-24T01:15:30.083
1

A hex colour such as #FCFCFC consists of three pairs representing RGB. The second part of each pair can be reduced to darken any colour without altering the colour considerably.

eg. to darken #FCFCFC, lower the values of C to give #F0F0F0

Reducing the first part of each pair by a small amount will also darken the colour, but you will start to affect the colour more (eg. turning a green to a blue).

answered 2009-11-24T00:58:21.257

Your Answer