As the United States grew, so did its rivalry with Mexico.
In 1803, the US bought the Louisiana Territory from the French, essentially doubling its size overnight.
Thirty years later, in 1836, the Republic of Texas declared independence from Mexico and applied to join the United States - which was granted in 1845.
The annexation of Texas triggered the Mexican-American War.
Fun fact: Due to limited communication between the East and West coasts, it took three months for official confirmation that the war had started to reach California.
The war culminated in the fall of Mexico City and the granting of what are now California, Nevada, Utah, Colorado, Arizona, New Mexico, and Texas to the United States in 1848.
California officially joined the United States as the 31st state.
In 1846, American settlers had seized a Mexican barrack in Sonoma and raised a flag proclaiming the California Republic - this became the basis for the modern California state flag.