How does the formation of coal differ from that of natural gas and oil?
Coal is formed by ancient plant materials while oil and gas forms from, mostly, ancient algae and other micro-organisms found in ancient seas.
Coal forms on land in massive peat bogs that eventually get buried by the sea and other sediments are laid on top of them - after millions of years, the peat turns into coal
Oil and gas are derived from algae and other organisms living and dying in the oceans. They eventually get covered by other sediments and the whole lot turns to rock. But the oils and the gases from the dead algae eventually get squeezed up out of their original rock formation, migrate upwards in the sedimentary rock basin and then get trapped in a reservoir. See pics.
Do a Socratic search for a similar question, "How does the formation of coal differ from that of natural gas and oil?" which has already been answered.
Similarities: they are both formed from organic remains and both form under enormous pressures in a sedimentary sequence.
Differences: coal is formed from land-based plants in bogs and coastal swamps, while oil and gas are derived from tiny marine organisms, such as algae and phytoplankton.