The answer is; they use the Doppler shift effect.
The stars that are in the red spectrum of color are moving away from the observer while those in blue spectrum light are moving closer to the observer. This is because objects moving away from you shift to longer frequencies while those moving towards you to shift to shorter wavelengths.