Like the rest of Central America, Costa Rica never fought for independence from Spain. On September 15, 1821, after the final Spanish defeat in the Mexican War of Independence (1810–21), the authorities in Guatemala declared the independence of all of Central America. That date is still celebrated as Independence Day in Costa Rica, even though, technically, under the Spanish Constitution of 1812 that had been readopted in 1820, Nicaragua and Costa Rica had become an autonomous province with its capital in León.
Like other Central American nations, Costa Rica joined the short-lived First Mexican Empire of Agustín de Iturbide but, after its collapse in 1823, Costa Rica became, instead, a province of the new Federal Republic of Central America, which theoretically existed from 1823 to 1839, but which exercised a very loose authority over its constituent provinces, particularly the poor and remote Costa Rica. In 1824, the Costa Rican capital was moved to San José, leading to a brief outburst of violence over rivalry with the old capital,Cartago. While civil wars raged both among the provinces of the Federal Republic of Central America and between political factions within individual provinces, Costa Rica remained largely at peace.
The 1849 national coat of arms was featured in the first postal stamp issued in 1862
In 1838, long after the Federal Republic of Central America ceased to function in practice, Costa Rica formally withdrew and proclaimed itself sovereign. The considerable distance and poor communication routes between Guatemala City and the Central Plateau, where most of the Costa Rican population lived then and still lives now, meant the local population had little allegiance to the federal government in Guatemala. From colonial times to now, Costa Rica's reluctance to become politically tied with the rest of Central America has been a major obstacle to efforts for greater regional integration.