When charged particles from the magnetosphere collide with atoms in the earth's upper atmosphere, they absorb extra energy that is expressed as light.
As the sun causes hydrogen and helium to fuse, protons and electrons are shot into space. Known as the solar wind, this stream of particles blows past the earth. As they blow past the earth, the earth's lines of magnetism draw the particles toward the north and south magnetic poles, where these lines converge.
When the particles arrive in the ionosphere, they collide with gas atoms and emit light. The color of light they emit depends upon the type of gas the particles collide with.
Light that is dominated by emissions from atomic oxygen causes a greenish and dark-red glow.
Blue light is a result of atomic nitrogen, while purple light is the result of molecular nitrogen.
Many other colors can also be seen.