Observational astrophysics

Why can astronomers use a star's absorption lines to identify elements in its atmosphere?