How do hydrangeas change colour?

Did you know that a hydrangea’s flower colour can actually change depending on the soil they’re planted in? It sounds like garden magic, but it’s all down to science.