We can determine the composition of stars through a technique called spectroscopy. By analyzing the light emitted or absorbed by a star, astronomers can identify the elements present in its atmosphere. Different elements produce distinct patterns of spectral lines, allowing us to understand the composition of stars.