Even though a planet is so much smaller than its star, it still exerts a tiny gravitational tug on the star as it orbits. When a planet is behind its star (from our point of view), it pulls the star slightly away from us. When the planet is in front of its star, it pulls the star slightly toward us. This causes the star to wobble ever so slightly back and forth. Most planets have been discovered after astronomers caught this wobble.
Powerful telescopes equipped with a spectrograph can detect a star’s to-and-fro motion by examining the star’s light. A spectrograph, like a prism, splits a star’s light into its component colors, producing a spectrum. Some of the starlight gets absorbed as it passes through the star’s atmosphere, though, and this produces small, dark gaps or lines in the spectrum. As the star moves closer to us, these lines shift just a smidge toward the blue end of the spectrum. As the star moves away, the lines shift back toward the red end of the spectrum. Astronomers can look for orbiting planets by looking for these back-and-forth motions of the lines in a star’s spectrum.