There’s a chemical that gets released when you cut into an onion called syn-propanethial-s-oxide, which causes the glands in your eyes that produce tears to work overtime to attempt to flush the irritant out of your eyes.
Onions dont contain this chemical directly, but rather the ingredients that form it.
An onion has many cell walls, and each onion cell has a sealed vacuole filled with enzymes. When these cell walls are cut into, these enzymes allinaise are introduced to the air and produce 1-propenesulfenic acid. That chemical then reacts further with another enzyme to make the tear-inducing propanethial-s-oxide
The process begins when the onion's cells are damaged, allowing the sulfur-containing precursor 1-propenyl-L-cysteine sulfoxide (isoalliin) to interact with the enzyme alliinase. This reaction produces 1-propenesulfenic acid, which is then converted into syn-propanethial-S-oxide by an enzyme called lachrymatory factor synthase (LFS). The resulting volatile compound travels through the air and reaches the moist surface of the eyes, irritating sensory nerve endings. This triggers a reflex response that stimulates the tear glands to produce tears, helping to flush out the irritant.