Earthworms have muscles which help to extend and shorten the body. During locomotion, the earthworm first extends the front part of the body, keeping the rear portion fixed to the ground. Then it fixes the front end and releases the rear end. It then shortens the body and pulls the rear end forward. Repeating such muscle expansions and contractions, the earthworm moves forward.
Its body also secretes a slimy substance which help in locomotion.
Earthworms have tiny bristles under their body which help to get a good grip on the ground.