When magnesium reacts with hydrochloric acid, hydrogen gas and soluble magnesium chloride are produced according to the following equation:
`Mg_((s)) + 2 HCl_((aq)) -> MgCl_2_(aq) + H_2_(g)`
The H2 bubbles can be seen forming but the magnesium chloride that forms remains in solution and isn't visible. You will observe the magnesium metal being consumed.
This is an example of a single replacement reaction. It takes place because magnesium is more reactive than hydrogen so it displaces it in the chloride compound. Magnesium is oxidized, losing two electrons. Hydrogen is reduced from H+ ion to H2 gas when the elecrons from magnesium are transferred to it.