West Virginia became a state in 1863; as a predominantly pro-Union area its citizens voted to secede from Virginia even as Virginia was voting to secede from the Union. Union troops occupied most of West Virginia in late 1861, and Congress approved its admission as a state. This was a political move that was backed by most of the population in the area.
The state capital moved back and forth between Charleston and Wheeling several times, until Charleston was named as the permanent capital in 1877 by a popular vote. The current capitol building was constructed in 1932.