Coal forms when vegetation partially decays in low-oxygen environments, such as swamps. Burial heats and compacts the plant matter, squeezing out water and gases (like methane) while leaving behind carbon. Thus, as the coal increases in rank, its carbon content--and the amount of energy it holds--goes up while its water content goes down.
The coal rank order is: Peat → Lignite (brown coal) → Bituminous coal → Anthracite
To reach the highest coal rank, anthracite, burial depths of up to 10 km are needed. These can be provided by an orogeny (mountain-building event). The Alleghanian Orogeny (which formed the Appalachians) in eastern North America metamorphosed plant deposits from the Carboniferous--a period when the land was covered with forests of large ferns and scale trees--providing the anthracite coal found in Pennsylvania. With even more heat and pressure, anthracite will turn into graphite, which is pure carbon.
You can read more about this process here, including additional information on the ranks, such as common uses of each rank and where to find deposits.