If some EM wave with continuum spectrum passes through some low pressure atoms (e.g. the outer atmosphere of a star), those atoms will absorb the light it likes and creates an absorption line. Similarly, if some low pressure atoms emit EM wave, they will create emission lines. Different elements will have different sets of lines. By carefully analyzing the spectrum of a star, we can tell which elements the star's surface may contain.