The hydrangeas are piled high in these early days of summer, blossom upon showy blossom, like so many fat dollops of cotton candy. And much like that sugary boardwalk treat, the color scheme for many varieties of these popular flowers runs from blue to pink, sometimes even within the same plant.

Many gardeners know that the acidity of the soil helps determine the color of this eye-popping garden feature. But scientists have shown the full story is more complicated, hinging on a substance more commonly associated with soda cans: aluminum.

Surprised? Chemist Henry Schreiber, a leading expert on the topic, initially felt the same way.

"I thought that was the craziest thing I'd ever heard," said Schreiber, a longtime professor of chemistry at Virginia Military Institute.

Schreiber, who retired in 2014 but still has 100 hydrangeas at his farm in Lexington, Va., recently helped explain the colorful science for a new video from the nonprofit American Chemical Society and PBS Digital Studios.

Here is the short version:

Aluminum, which is commonly present in backyard soil, is toxic to hydrangeas. Yet the plants are protected from the metal's damaging effects in one of two ways.

When the soil is alkaline, with a pH above 7, the aluminum binds to hydroxide ions in the ground. The resulting "complex" does not dissolve in water, so it is not readily taken up by the plant's roots. No danger. The plant's sepals — the colorful appendages at the top of the plant — retain their "natural" color of pink or red.

At Primex Garden Center, this variety of hydrangea, called Everlasting Harmony, appears pink, suggesting that its soil is alkaline.
MICHAEL BRYANT / STAFF PHOTOGRAPHER
At Primex Garden Center, this variety of hydrangea, called Everlasting Harmony, appears pink, suggesting that its soil is alkaline.

But when the soil is acidic, with a pH below 7, aluminum can dissolve in the water supply, requiring the plant to mount an active defense. Weirdly, that process involves drawing the toxic danger inside.

First, the hydrangea secretes still more acid into the soil — in the form of citric acid, which binds to the aluminum to form aluminum citrate. That substance is then drawn up through the plant's roots to the sepals, where it binds to the plant's reddish pigment in such a way that the aluminum is no longer toxic. But that new complex — the chemical marriage of aluminum citrate with the red pigment — just happens to look blue.

The role of aluminum in hydrangea color was first reported in the mid-20th century, but it took several decades for scientists to determine exactly how it worked. When Schreiber came to the problem after 2000, he was skeptical of the aluminum theory, predicting that the cause might instead lie with iron or copper — other metals in the soil that are more commonly associated with altering nature's colors.

Nope. Though Schreiber was able to alter hydrangea color slightly by manipulating levels of iron, aluminum turned out to be the key.

Home gardeners eager to change hydrangea color should not bother messing with the aluminum levels in their soil, however, said Ron Kushner, a horticulturist at Primex Garden Center in Glenside. The easiest method is to alter the soil's pH, thereby controlling how much aluminum dissolves, he said.

Those in search of blue flowers should add sulfur to make the soil more acidic — but do not overdo it, and expect to wait at least a month to see a change if the plant has already bloomed. For pink flowers, add lime, Kushner said. Violet results from a pH somewhere in between, depending on how much aluminum is in the soil.

This hydrangea in a Jenkintown yard is deep blue, suggesting the soil is acidic.
TOM AVRIL / STAFF
This hydrangea in a Jenkintown yard is deep blue, suggesting the soil is acidic.

Hydrangea color is a perennial topic of inquiry, the horticulturist said.

"This is just a constant barrage of questions from our customers," Kushner said. "Constantly, constantly, constantly."

The pink-or-blue chemistry applies only to certain varieties of hydrangeas. Others tend to appear white.

Schreiber has altered the color of those, too, but don't try this technique at home. In his lab, the chemist found he could make white hydrangeas turn bright yellow by adding another metallic element called molybdenum. But to perform this trick in a garden, he realized he would need to add so much molybdenum that it would poison the soil.

"I'd end up with a toxic waste dump," he said.

So for nature's cotton candy, the primary colors remain pink, blue, and white.