Solenoid valves open and close using magnetic force. When current flows through a coil, a magnetic field is generated. The magnetic field lines are concentrated inside the coil.
The magnetic circuit around a current-carrying coil tends to reduce its magnetic resistance and close the air gap: This increases the inductance, and a voltage is induced in the coil that has the same polarity as the supply voltage.
When the current is turned off, overvoltages can occur due to self-induction. These can lead to the destruction of the switch. Therefore, protective diodes are used in DC solenoids, and varistors are used in AC solenoids.