Unlike in most films, a lot of the chemicals commonly used in a lab are transparent liquids or white powders. This is for a number of different reasons, but generally speaking, colours in chemistry usually arise due to the presence of metals like iron, copper or chromium.
For instance, Corundum has the molecular formula $Al_2O_3$ and in its pure, mineral form, is a transparent/white crystal.
If we take this exact same mineral and introduce trace amounts of iron, titanium or chromium, we get vibrant blue and red crystals. In fact, the crystal forms of corundum with trace amounts of iron and titanium, and chromium, respectively, are what we know as sapphires and rubies.
These colours arise as the result of electron transitions within the metal impurities. In a similar way, many of the common coloured substances one encounters in chemistry labs are compounds which are structurally composed of metal centres surrounded by a number of substituent groups called 'ligands'. These complexes are called metal (or 'coordination') complexes.
What is a Metal Complex?
A metal complex is a compound consisting of a central metal atom or ion surrounded by several atoms, ions or molecules known as ligands. Common examples of metal centres might include gold, chromium, nickel, copper, iron or platinum, and the ligands themselves may be halides, ions like cyanide, hydroxide or oxalate, or neutral compounds like water, carbon monoxide or phenyl groups.
The specific chemistry that governs which ligands bond to which metal centres is based primarily on acid-base theory, specific Lewis acid-base theory. The metal centre acts as a Lewis acid, and accepts electrons from the ligand, acting as a Lewis base. The bonds that form as a result of this interaction are generally classed as covalent bonds.
The Effect of the Ligands
As the ligands bond to the metal centre, they bring with them clouds of negative charge in the form of their donated electron pair. Since the metal centre already has a number of its own electrons, specifically those in its d-orbitals, this introduces a form of electrostatic repulsion between the metal's and ligands' electrons. This is complicated slightly more by the fact that the metal's d-electrons are not arranged evenly around the metal, but instead in the 5 orbital shapes shown below, each housing up to 2 electrons.
As the ligands attach, some of the orbitals shown above will be closer to the ligands' electrons than others, leading to more repulsion and overall higher-energy orbitals. (This depends, of course, on the geometry of the ligands themselves, since surely if 4 or 6 ligands attach, they'll arrange in different ways? This is true, though for simplicity, we'll look at the most common case, octahedral complexes, wherein 6 ligands arrange evenly around a metal centre.)
As such, when these ligands bond to our centre, what we observe is a 'splitting' of the d-orbital energies, where $d_{x^2-y^2}$ and $d_{z^2}$ orbitals, closer to the ligands' electrons, end up with higher overall energies than the others. We can represent these energy differences with a splitting diagram which is covered below.
d-Electron Splitting Diagrams
To visualize the uneven repulsion and subsequent energy splitting explained above, we use diagrams showing the various energies of the metal's d-orbitals. An example is shown below.
As we can see, an energy difference exists between electrons in lower and higher energy orbitals. As one might imagine, this leads to the possibility of electron transitions. Indeed, when visible light hits a metal complex, the electrons in lower energy orbitals may excite to the higher energy ones, and upon relaxing back to their original orbitals, release photons of light. Since the energy (and thus wavelength) of the light depends on the exact energy split of the metal complex, this corresponds to a specific colour. For instance, a cobalt metal centre, surrounded by amine ($NH_3$) ligands is a bright yellow/orange colour.
In summary, metal complexes allow for entire new avenues of chemistry to be explored, and are an incredibly useful and unique class of substances. As a final note, one might notice that the splitting diagram above is labeled as being "high spin". Without going into too much detail, the extent of repulsion and subsequent d-orbital splitting in metal complexes can lead to metal complexes wherein electrons fill all the bottom orbitals first, or those where all orbitals are filled before being paired. We call these, respectively, low and high spin complexes. This is mainly due to the extent of the energy splitting, which depends on both the nature of the ligands themselves, and to a lesser extent, the metal centre.
The "spectrochemical series" is an ascending list of ligands ordered in terms of "field strength", or how much they split metal's d-orbitals in these complexes. We can use this series to predict what the electron configuration may be in various different metal complexes with the general rule being what we might expect: the higher the extent of the orbital-splitting, the more likely we are to observe a low-spin complex.
Try out the metal complex builder to experiment with building and visualizing different metal complexes, including their IUPAC names and d-electron splitting diagrams. In addition, the interactive spectrochemical series allows one to explore the splitting capabilities of all common ligands, and see examples complexes in which they might be found.