Mars's trajectory seems to go backward periodically. This is called a retrogradation (or retrograde motion). Because the Earth orbits 1.88 times faster than Mars, the relative motion of both explains this phenomenon.
The animation is not drawn to scale, for either sizes or distances.