Algae and plants lived in shallow seas millions years ago .After dying and sinking to the seafloor, the organic material mixed with other sediments and was buried .Over millions of years under high pressure and high temperature, the remains of these organisms transformed into what we know today as fossil fuels. Coal, natural gas, and petroleum are all fossil fuels that formed under similar conditions.
hope it helps