Examining visible light from the sun and other stars has shown lines in space called absorption lines. These patterns of lines help to reveal that certain elements in the sun act like fingerprints for atoms and absorb colors of light. On top of elements absorbing atoms the atmosphere has also shown to not allow certain wavelengths pass into the earths atmosphere and prohibit colors on the spectrum.
Visible light is created by "exciting" of electrons in atoms or molecules by electric effects of collisions caused by heat and then "falling" back, shedding the energy difference in the form of a photon.