If a star is moving toward Earth, its light waves appear to be squeezed together. The decreasing distance between Earth and the star effectively shortens the wavelength of the starlight received by Earth. This shifts the star's spectral lines toward the blue end of the spectrum. If the star is moving away from us, its waves are effectively stretched out when they reach Earth, increasing their wavelength. This shifts the star's spectral lines toward the red end of the spectrum.
The dark lines in stellar spectra are caused by the absorption of specific wavelengths of energy by elements in the star's outer levels. Identifiable patterns of absorption lines that appear at shorter or longer wavelengths than normal indicate that the star is moving. The greater the shift from the normal position of the lines, the faster the star is moving.
In the visualization, the bottom spectrum shows the "normal" postion of absorption lines for a star that is not moving toward or away from Earth. The top spectrum simulates absorption lines for stars that have the motion and speed indicated by the controls.
! Click the "away" or "toward" button, then click on the arrows under the speedometer to change the star's speed relative to Earth.