How can astronomers determine a star's chemical composition?
Spectroscopy is a method that is usually used by scientists to determine the composition, mass and also the temperature of Objects in the observable universe.
Scientist usually take a spectrum of the object they are observing using a spectrograph. This is based on the principle that the absorption lines are unique for every element at a particular wavelength.
The above image is a spectrum of our Sun. You can see the visible light spectrum of the Sun all the way from Blue to Red. The important thing to notice is the dark lines within the spectrum. Each dark line occurs at a particular wavelength which helps in determining which element is present inside the object. These lines can be seen as the fingerprints of elements.
Refer to the Image below the colorstrip. The sharp bends are the absorprtion lines.
Let's try to understand this with the help of an example.
Let's imagine that you obtain a Spectrum of a Sun like Star or anyother object in the universe. Now if you want to find out the composition of a Star you're gonna have to look at the absorption lines as they always occur at a particular wavlength. for. example the absorption line for hydrogen, if the hydrogen is present in the object will always appear at about 656.3 nm as also shown in the above figure.
This means that if Hydrogen is present in a Star you will get an absorption line at about 656.3 nm. But this is only true for our Sun. For other objects this wavelength may have a slight discrepancy due to Red or Blue Shifts.