When enormous pressure is placed on carbon under extreme temperatures (100 miles below the Earth's surface, for example, where the temperature is between 2,000 and 2,600 degrees Fahrenheit), the structure hardens to form a diamond. Other substances and gases trapped inside the diamond give it its color. Diamonds are colorless only when there are no extra elements trapped inside the carbon structure.
As the carbon is being pressurized, the oxygen in its environment has significant influence. Carbon forms into a diamond within a range of parameters for substrate temperature, methane concentration and reaction pressure. Oxygen extends those parameters, increasing the growth rate of diamond and suppressing the production of graphite--a mineral created just like a diamond is but with looser connections among the carbon atoms.
During formation of a diamond, oxygen plays a role in modifying the gem's structure. Experiments on synthetic diamonds show that even tiny amounts of oxygen dramatically improve a diamond's visible intensity (sparkle), as well as its hardness, density, transparency and diffusion.