Coal measures are formed like this. A low-lying tropical swamp or rain forest forms a peat swamp which is short of oxygen. Dead plant material builds up, and does not decompose entirely. The plant material gets buried as a peat bog. From time to time rivers bring down a load of sediment from nearby mountains, covering the swamp. Eventually layers of coal alternate with layers of sandy deposit. Pressure turns it all into hard rock. Later on, the rocks are uncovered by erosion, and fossils can be found by humans.