view the rest of the comments
Ask Science
Ask a science question, get a science answer.
Community Rules
Rule 1: Be respectful and inclusive.
Treat others with respect, and maintain a positive atmosphere.
Rule 2: No harassment, hate speech, bigotry, or trolling.
Avoid any form of harassment, hate speech, bigotry, or offensive behavior.
Rule 3: Engage in constructive discussions.
Contribute to meaningful and constructive discussions that enhance scientific understanding.
Rule 4: No AI-generated answers.
Strictly prohibit the use of AI-generated answers. Providing answers generated by AI systems is not allowed and may result in a ban.
Rule 5: Follow guidelines and moderators' instructions.
Adhere to community guidelines and comply with instructions given by moderators.
Rule 6: Use appropriate language and tone.
Communicate using suitable language and maintain a professional and respectful tone.
Rule 7: Report violations.
Report any violations of the community rules to the moderators for appropriate action.
Rule 8: Foster a continuous learning environment.
Encourage a continuous learning environment where members can share knowledge and engage in scientific discussions.
Rule 9: Source required for answers.
Provide credible sources for answers. Failure to include a source may result in the removal of the answer to ensure information reliability.
By adhering to these rules, we create a welcoming and informative environment where science-related questions receive accurate and credible answers. Thank you for your cooperation in making the Ask Science community a valuable resource for scientific knowledge.
We retain the discretion to modify the rules as we deem necessary.
There are many ways to do spectroscopy because of the wide range of wavelenghts of light. I won't go into detail, but essentially what spectroscopy does is either:
The reason those two methods produce characteristic results for each element is the following: An atom is made up of a nucleus of a certain charge and electrons canceling that charge around it. Those electrons are confined to so-called orbitals due to quantum weirdness (the "quantisation" of the orbitals is literally the origin of the word quantum). Those orbitals have different energies (you can imagine that an electron being very close to the nucleus is more strongly attracted than an electron which is farther away).
Because the electrons need to always be on those orbitals with fixed energies, only certain energies of photons can interact with them (if a different energy photon wanted to interact with an electron it would need to push the electron "between" two orbitals which is forbidden by quantum mechanics)
So now only certain energies of photons (which relate directly to wavelength) are absorbed, the rest passes uninterrupted leading to bands in the spectrum where lots of photons are absorbed.
Now depending on how many electrons your atom has and how far away they are from the nucleus those absorbtion bands will vary, giving you a good idea which atom you are looking at.
Emission spectroscopy works the other way around, instead of you seeing what is absorbed, you randomly put energy (often using heat) into the atom. When the atom wants to go back to its most stable state it has to emit a photon, this photon needs to correspond to a gab between two orbitals (because else the electron either starts or ends outside of an orbital (which is forbidden))
For molecules the elecyrons of the individual atoms are mixed together into their own molecular orbitals that follow the same logic the commenter above had written with respect to energy levels and photons.
I'm specifying this because the OP was asking about individual elements within a molecule, and that's not how that works. The electrons are shared so you don't get the emissions from the elements composing the atoms in the molecules on their own.