How did Costa Rica achieve its independence from Spain?

Created from Britannica articles using AI. AI can make mistakes, so verify using Britannica articles.

Costa Rica's independence from Spain was a consequence of Mexico's declaration of independence in 1821. Following this, Costa Rica, along with other Central American regions, became part of the short-lived Mexican Empire. In 1823, Costa Rica was instrumental in forming the United Provinces of Central America. However, due to internal conflicts within the federation, Costa Rica withdrew in 1838, reinforcing a pattern of isolationism that characterized its colonial period and continued for much of the 19th and 20th centuries.12