Here is a very simplistic explanation of Spectroscopy:
This image was photographed through a basic Science class 100 line resolution Quantitative Spectrometer, but with higher resolution Spectrometers, Astronomers can determine what chemical elements stars and planets are made of, as each chemical element has a unique light absorption fingerprint in the spectrum. The amount that the absorption lines are shifted to red or blue (redshift and blueshift), is due to the Doppler effect and gives an indication if the celestial object is moving towards or away from us, and at what speed. This is how Scientists know what the observable Universe is made of, and that the Universe is expanding.
OLYMPUS DIGITAL CAMERA