2HCl + Mg → H2 + MgCl2
In this reaction, the hydrochloric acid donates hydrogen ions (H+) to the magnesium, which then combines with the chloride ions (Cl-) from the hydrochloric acid to form magnesium chloride. The hydrogen ions and electrons released by the magnesium atoms combine to form hydrogen gas.
The reaction between hydrochloric acid and magnesium is an example of a single-displacement reaction, where one element (magnesium in this case) replaces another element (hydrogen) in a compound (hydrochloric acid).