A magnetic field can also be used to focus charged particles. The Lorentz force acting on the electron is perpendicular to both the direction of motion and to the direction of the magnetic field (vxB). A homogeneous field deflects charged particles, but does not focus them. The simplest magnetic lens is a donut-shaped coil through which the beam passes, preferably along the axis of the coil. To generate the magnetic field, an electric current is passed through the coil. The magnetic field is strongest in the plane of the coil and gets weaker moving away from it. In the plane of the coil, the field gets stronger as we move away from the axis. Thus, a charged particle further from the axis experiences a stronger Lorentz force than a particle closer to the axis (assuming that they have the same velocity). This gives rise to the focusing action.  Unlike the paths in an electrostatic lens, the paths in a magnetic lens contain a spiraling component, i.e. the charged particles spiral around the optical axis. As a consequence, the image formed by a magnetic lens is rotated relative to the object. This rotation is absent for an electrostatic lens. 
The spatial extent of the magnetic field can be controlled by using an iron (or other magnetically soft material) magnetic circuit. This makes it possible to design and build more compact magnetic lenses with well defined optical properties. The vast majority of electron microscopes in use today use magnetic lenses due to their superior imaging properties and the absence of the high voltages that are required for electrostatic lenses.