When following another vehicle, you should leave enough space between both cars so that you have time to react if the vehicle in front of you suddenly brakes or changes direction. The "two-second rule" is a common guideline for following distance: pick a fixed object on the side of the road, and count the number of seconds between when the vehicle in front of you passes it and when you pass it. If it takes less than two seconds, you are following too closely.
This following distance is recommended in ideal conditions, but you may need to increase the following distance in adverse conditions, such as low visibility or slippery roads.