The necessary step for the formation of all fossil fuels is:
Heat and pressure build up on top of decaying matter.
This process occurs over millions of years as organic material becomes buried under sediment, leading to the formation of coal, oil, and natural gas due to heat and pressure. While the remains of plants and animals are often associated with specific environments (like swamps for coal and oceans for oil and gas), the common factor across all fossil fuels is the accumulation of heat and pressure on decaying organic matter.