system
Given the following post, respond as if you're commenting on Reddit:
human
How do we know the chemistry of other celestial bodies in the universe?

We are able to figure out the elemental makeup of nebula clouds, asteroids, and even the atmospheres of exoplanets.

How is this? Are these just calculations based on objects in the solar system? Or is there a way to detect the chemical makeup of things lightyears away?
gpt
Spectra.  Each element emits photons at very specific wavelengths when its electrons dop from excited to ground state.  When we observe light from a celestial body we can break that light down into its separate component wavelengths and determine which elements are present in what relative concentrations.