DEV Community

Colin Shanley
Colin Shanley

Posted on Originally published at Medium on

Calculating tints, shades and tones by hand

A little white, a little black, a little maths.

Colourcast colour mixer

By hand? Well, maybe not. But using a calculator with equation support, you can certainly craft tints, shades and tones the old fashioned way. Or use an application to do it for you.

Getting the balance right for elements of a digital colour palette can be a tricky business. You may need variations of the base colour for data or surface backgrounds. But probably the most obvious application is interactive design (e.g., what does a hovered button look like?). This is where tints, shades and – to a much lesser extent – tones come in.

The difference between these three, although very simple, is often misunderstood:

  • A tint is a base colour mixed with white. So it becomes progressively lighter.
  • A shade is a base colour mixed with black. So it becomes progressively darker.
  • A tone is a base colour mixed with mid grey (#808080). So it becomes progressively less saturated.

Say you want a button to be lighter when the pointer hovers over it – then you need a tint of the base colour. Conversely, you need a shade if you want the button to be darker on hover.

That percentage shift – lighter or darker – is controlled by mathematical formulas that are little known.

Calculating a tint

Say you want your button to become a little lighter when the pointer hovers over it. Mixing its base colour with 20% white gives you quite a differentiation, which may be a nice hover colour for your project.

As you may well know, the three RGB numbers, called channels, run from 0 to 255. White is RGB (255, 255, 255), so adding white means moving all three numbers towards 255. The formula is:

C = V + (255 − V) × (p ÷ 100)

  • C is the new channel value.
  • V is that channel’s base value.
  • p is the percentage of white in the mixture.

Apply the formula three times: once for red, once for green and once for blue. Admittedly, that is a little cumbersome with a calculator, but at least you’ll acquire a sense for what is going on.

Example: adding 20% white

Take the base colour of RGB (91, 127, 138) or #5B7F8A. The mixture we want as a result will contain 80% base colour and 20% white.

Start with red, whose value is 91:

  1. Subtract 91 from 255. That leaves 164.
  2. Find 20% of 164: 164 × 0.20 = 32.8.
  3. Add that to the original value: 91 + 32.8 = 123.8.
  4. Round to the nearest whole number: 124.

Repeat for green and blue. The complete calculations are:

  • Red: 91 + (255 − 91) × 0.20 = 123.8, rounded to 124.
  • Green: 127 + (255 − 127) × 0.20 = 152.6, rounded to 153.
  • Blue: 138 + (255 − 138) × 0.20 = 161.4, rounded to 161.

Your new colour is RGB (124, 153, 161) (or #7C99A1). That is your base colour mixed with 20% white.

Increase the percentage for a paler tint. At 0%, you have the original colour; at 100%, you have white.

Calculating a shade

Conversely, you may want a button to become darker when the pointer hovers over it. This time, mix the base colour with black. The process is much the same, although the formula obviously differs:

C = V × (1 − p ÷ 100)

  • C is the new channel value.
  • V is that channel’s base value.
  • p is the percentage of black in the mixture.

Again, you apply the formula separately to red, green and blue. For 20% black, you retain 80% of each base channel value. So you can simply multiply each by 0.80.

Example: adding 20% black

Take the same base colour as before – RGB (91, 127, 138) or #5B7F8A. The mixture we want will contain 80% base colour and 20% black.

Start with red (value of 91):

  1. Divide the percentage by 100: 20 ÷ 100 = 0.20.
  2. Subtract that from 1: 1 − 0.20 = 0.80.
  3. Multiply the original value by 0.80: 91 × 0.80 = 72.8.
  4. Round to the nearest whole number: 73.

Repeat for green and blue. The complete calculations are:

  • Red: 91 × (1 − 20 ÷ 100) = 72.8, rounded to 73.
  • Green: 127 × (1 − 20 ÷ 100) = 101.6, rounded to 102.
  • Blue: 138 × (1 − 20 ÷ 100) = 110.4, rounded to 110.

Your new colour is RGB (73, 102, 110) (or #49666E). That is your base colour mixed with 20% black.

Increase the percentage for a darker shade. At 0%, you have the original colour; at 100%, you have black.

Calculating a tone

As a personal preference, I am not too keen on using tones in interactive colours. But they are excellent for backgrounds, surfaces, or data ranges. To create a tone mix your base colour with mid-grey: RGB (128, 128, 128) or #808080. The formula is:

C = V + (S − V) × (p ÷ 100)

  • C is the new channel value.
  • V is that channel’s base value.
  • S is the mid grey channel value, here 128.
  • p is the percentage of grey in the mixture.

As with a tint, apply the formula three times. Each channel moves towards 128. Values below 128 increase; values above 128 decrease. A value already at 128 stays unchanged.

Example: adding 20% grey

Again, take the base colour as before – RGB (91, 127, 138) or #5B7F8A. The mixture we want will contain 80% base colour and 20% mid grey.

Start with red, whose value is 91:

  1. Subtract 91 from the grey value: 128 − 91 = 37.
  2. Find 20% of 37: 37 × 0.20 = 7.4.
  3. Add that to the original value: 91 + 7.4 = 98.4.
  4. Round to the nearest whole number: 98.

Repeat for green and blue. The complete calculations are:

  • Red: 91 + (128 − 91) × 0.20 = 98.4, rounded to 98.
  • Green: 127 + (128 − 127) × 0.20 = 127.2, rounded to 127.
  • Blue: 138 + (128 − 138) × 0.20 = 136.0, giving 136.

Notice that red increases while blue decreases. Both move closer to the grey value of 128.

Your new colour is RGB (98, 127, 136) (or #627F88). That is your base colour mixed with 20% mid grey.

Increase the percentage to move further towards grey. At 0%, you have the original colour; at 100%, you have #808080.

Colourcast colour mixer

Conclusion

With these formulae saved in your calculator’s memory, you can work out the sRGB colours for your interactive states: hover, pressed, selected and so on. Adjust the percentages, calculate each channel and put the resulting colour into your design.

It works. But it is not exactly the most visual of methods. A set of RGB values tells you little about how those colours sit together, and repeating the calculations for every variation soon becomes tedious, to say the least.

This is where Colourcast, a native macOS application, comes in. Choose a base colour and it generates your tints, shades and tones for you, displayed as swatches you can compare at a glance. Adjust the colour, choose how many swatches you want, save the results in palettes and copy the colour values into your design or code. That said, it is useful to understand the formulas to gain insight into the process.

Colourcast website


Colin Shanley has been an author for more than 30 years. You can follow his Medium articles.

Top comments (0)