Coastal peat swamps build up over time, are buried by rising sea levels and eventually get compressed into coal.
Coal starts off as vegetative that forms often in coastal regions. Over long periods of time, this plant material lives and dies and gradually builds up into thick peat deposits. Sea levels then often rise burying the peat and sediments are gradually laid on top of the peat. This goes on for millions of years and more and more sediments continue to bury the peat.
Gradually, the water in the peat gets squeezed out and the peat becomes lignite coal. The sea levels gradually drain away. With more and more burial, the lignite might become sub-bituminous coal then bituminous coal and even anthracite. But this “coalification” process could stop at any of these stages and all peat need not necessarily go all the way to anthracite.