If you're in a vehicle and you're hit from behind, your body is pushed forward quickly. As your body pitches forward, your neck extends as far as possible forward, stretching the soft tissue, and then when it reaches as far as it can go, your neck snaps back. The force of snapping forward and then backwards is what causes the damage in your neck, whiplash.
Treatment of whiplash is quite simple and involves keeping your neck still. This means wearing a soft brace or cervical collar to keep your head in position. This can take a few weeks. Your doctor might prescribe some medication for the pain and to relax the muscles, heat therapy and/or physical therapy.