Yes, they can. Spectroscopy is using the emission and absorption lines in the electromagnetic spectrum to find out the composition of distant celestial objects.
When light strikes an atom, part of the light is being absorbed and so the spectrum you get has dark lines (called absorption lines) in some parts.
Each atom absorbs light of different frequencies (different colors), thus each element has its own "fingerprint". So the spectrum you get will be unique and you will be able to identify which atom (of which element) absorbed it.
When light is being emitted by the same atom, light of the same frequencies is emitted as of this which was absorbed.
So you can understand that knowing the absorption or emission lines means you know the responsible elements!
As a result, you can find out the composition of the celestial object you are studying.