The 19th Century went down in history as one marked by turmoil, revolution, independence and many changes. It was no different for Spain.
At the beginning of the century, Napoleon continued expanding his empire. Though he played at being friends with the Spanish monarchy, going as far as signing treaties to ensure the alliance between the two countries, he proved to be a rather treacherous one.
Napoleon wanted total control of Europe and with Portugal's alliance with England (which meant the Brits had complete use of the Portuguese ports) his ambitions were frustrated. The French and the Spanish initiated a campaign against the Iberian country, the so called War of the Oranges, which luckily was short lived and left hardly any casualties.
In the end it turned out Spain was included in the French Emperor's designs and they carried out a Spanish and French Invasion of Portugal again a few years later and while on their way, under Napoleon's command the French troops "peacefully" occupied Spain which resulted in one of the bloodiest civil wars of the century: the Popular War in which the Spanish population rose in arms against the French military forces and developed the warfare "guerrilla", which entendered the Spanish vocabulary and is now part of many languages and the emblematic Battle of Bailen
Unfortunately the war against Napoleon and his French invasion was not the only one to devastate Spain in their own lands. Soon other civil wars followed. Inspired by the French revolution a large liberal movement in Spain wanted to get rid of the Monarchy. They believed that royalty was an archaic form that proved to be a burden that stopped the country's way into progress.
In 1820 a huge military uprising took place and declared the Cadiz constitution from 1812 valid. It was one of the most liberal constitutions the world seen. At Ferdinand VII's request there was a French invasion in Spain, in campaign known as Hundred Thousand Sons of Saint Louis. After this the monarchy was restored.
But Spain had not seent the end of it. On the third decade of the century a new problem in relation to the succession arose. The king's heir was a girl, and women were forbidden from the throne. Ferdinand VII changed this however, rendering the so called Salic law null and void - thus ensuring that his daughter became Queen in her own right.
This was disputed by her uncle, Carlos, who became a pretender for the throne and his supporters are known as Carlists, and the First Carlist War begins, followed by the second, also called War of the Matiners when Carlos' second attempt at having access to power by marrying his son off to Isabella failed, and a Third Carlist War when Carlos's son (also Carlos) had a go himself at trying to seize the crown.
Many believed that their territories in the Americas were i less peril than any summer camp; but they could not be more wrong. Many countries in South America became independent in the first half of the 19th century, such as Chile, Argentina, Bolivia and Mexico, and the ones that remained wanted to become nations in their own right too. However there would be one more Spanish war episode in the century, the Spanish South American war.
Dominican Republic had already broken off from Spain, but in 1860 the newly elected President sent a long and tearful letter to the Queen begin her to take them back and probably became the only country to be re-annexed into an empire voluntarily. The queen agreed but it was no sweet bed of roses for the Dominican's and soon they were fighting for their independence again in the Dominican Restoration War.
On the other hand in Spain's African colony things were complicated as well. Several attacks on the Spanish cities Ceuta and Melilla lead into the military conflict known as the Spanish-Moroccan war, which ended in victory for the Spaniards.
By the end of the century Cuba and a bunch of other nations were still property of the Spanish crown, becoming it's wealthiest colony. But the Cubans were fed up and in 1864 began a long battle to get rid of them, the 10 Year War which Cuba lost. But that was not the end of it. A few years later the Cubans asked the US to intervene. This resulted not only in Cuba's independence, but also the American Spanish War.
In consequence of the war against America, Spain lost almost all of its colonies including the Philippines, effectively ending a long period of grandeur, influence and wealth of the European kingdom.