Traces of nitrogen make diamonds yellow while traces of boron make them blue. What accounts for the differences in color for a given element?
If you had googled a little bit you would have found this wonderful resource.
In a yellow diamond, a few carbon atoms per million have been replaced by nitrogen atoms, each containing five valence electrons. The structure of the diamond crystal does not change significantly, but the extra electrons occupy a donor level.
The nitrogen donor level energy in a diamond is large, peaking at about 4 eV. With a concentration of a few nitrogen atoms per million, instead of a clean "spike" donor level energy, the nitrogen donor level energy broadens into a band because of a number of complex factors, including thermal vibrations. This broadened donor energy band results in the difference between donor and conduction bands being as low as 2.2 eV. The most likely transition allows incident light with energy of 4 eV per photon to excite electrons from the donor level to the conduction band. However, it is possible for electrons to be excited to the conduction band with energy of 2.2 eV and upwards. This means that blue and violet light are absorbed from the full spectrum of light normally transmitted, and the resulting color is yellow.
Unlike blue boron-doped diamonds, which conduct electricity, nitrogen-doped diamonds remain insulators. This is because nitrogen is a deep impurity: a relatively high energy (2.2 eV, as compared with 0.4 eV for boron) is required to excite electrons from the donor energy level to the conduction band, and only a fraction of the available electrons are freed to carry a charge.
An extremely rare green color can result from a higher nitrogen content of about 1 atom per 1000 atoms of carbon. At even higher nitrogen concentrations, the donor level broadens so that all visible light can be absorbed, resulting in a black color.
Synthetic blue diamonds are created by adding boron as an impurity. Boron is trivalent, having three valence electrons; where a boron atom replaces a carbon atom in the diamond structure there is one fewer electron than usual. This missing electron, or hole, creates an acceptor energy level above the valence band. The boron acceptor energy is only 0.4 eV, so light of any energy can be absorbed during excitation. The boron acceptor band is broadened, and the absorption tapers off throughout the visible light energies, resulting in stronger absorption at the red end of the spectrum. At a level of one or a few boron atoms for every million carbon atoms, an attractive blue color results. Natural diamonds of this color, such as the Hope Diamond, are rare and highly priced.
There are two mechanisms by which diamonds can become colored. The first mechanism involves impurities. As the diamond crystal is growing, materials in the atmosphere or soil can become incorporated into the diamond structure. The bonds that form between carbon atoms adjacent to the impurity and the impurity can absorb photons and result in electronic transitions. If these transitions happen to occur in the visible region of the spectrum, then any reflected light will not contain the absorbed wavelength and the diamond will no longer appear white (as it does when all wavelengths are reflected).
A second mechanism that can impart color to diamonds involves structural deformation of the diamond crystal. As the diamond crystal is growing, tectonic forces or radiation can cause the diamond crystal to grow in an irregular manner. There are no impurities as described above, but a carbon atom may be missing here and there. These structural anomalies also result in a shift in the frequency of light absorption by the diamond. Again, if the light absorption shift is into the visible region, the diamond will appear colored.