Nature uses color in lots of different ways. In many animals, color camouflages the animal. In plants the opposite is more common -- color in flowers, for example, attracts insects to pollinate the flower. The purple color in red cabbage comes from a class of pigment molecules called anthocyanins. It turns out that anthocyanins are found in flower petals, leaves (it makes them turn red in the fall!) and some fruits such as blueberries. Anthocyanins are plant pigments known as flavenoids and produce red, pink, violet and magenta colors in the various plant parts.
The anthocyanidin group (See the sidebar below for the molecule structure) controls the color of the pigment. The electrons of the ring structures interact with incoming light and absorb various frequencies. (See How Light Works for a discussion of absorption.) The molecule shown below appears purplish red because its electrons absorb the yellow, green and blue portions of the visible spectrum.
One of the things that changes the color on anthocyanins is the level of acid or alkali (i.e., pH) around the molecule. Because the color of the anthocyanin is affected by the pH of the environment, these molecules can tell you the pH of any substance. If you make an extract of red cabbage juice, it will change color when mixed with solutions of various pH. The anthocyanin turns bright pink in acids, reddish-purple in neutral solutions and green in alkaline or basic solutions. This experiment shows you how to make a pH indicator from red cabbage!
Here is the generalized structure for a purplish red anthocyanin molecule.
Chemically, anthocyanins are made of a sugar molecule attached to a nonsugar part called anthocyanidin. This anthocyanidin has three rings, two 6-carbon (i.e. benzene) rings linked to another ring containing five carbons and one oxygen. The various anthocyanins differ from one another with respect to (1) the number and type of chemical groups, either hydroxyl groups (OH) or methoxy (OCH3) groups attached to the rings of the anthocyanidin and (2) to the sugar that forms the glycoside linkage (i.e. the bond between the sugar and the anthocyanidin).
Here are some interesting links: