The large land of Mexico was a Spanish possession from early on in the history of exploration of North and South America. This Mexico contained not only all of what is now Texas but also a large part of what is now other American states. Also included were many of the states that are part of Mexico today. In the early 19th Century, however, all of these areas were all part of a large land that had gained independence from Spain (in 1821) but that was having problems keeping its people happy.
Following the American example, Mexico drew up a Constitution, creating the United Mexican States. The resulting country (which had 19 states and four territories) was to have a two-house Congress, a Supreme Court, and an executive branch with the president as its head. The most well-known of the presidents of Mexico was Antonio Lopez de Santa Anna, who assumed the presidency in 1833.
An early ally of Emperor Agustin Iturbide (overthrown in the 1820s), Santa Anna was frustrated by the representative nature of the new form of government longed to return his country to a more centralized system of government. He got his chance when he was elected President in 1834. (He had actually been elected the year before but had turned over his duties to his vice-president in order to lead troops in battles against Mexico's neighbors.)
In 1835, Santa Anna declared the Constitution of Mexico null and void and set up a more authoritarian government, giving himself much more power. He had the army with him, so many Mexicans went right along. Many states wanted out, among them Texas. These other states wanted the Constitution reinstated. Texas wanted to be its own country.
The people of Texas at this time were, for the most part, whites who were living there to settle new land or to escape prosecution in America. Led by Sam Houston, they banded together and declared themselves independent on October 2, 1835. Tempers flared, and some strange actions resulted, including an argument over a cannon that resulted in the creation of a flag containing the words "Come and Take It," which came to signify the Texas spirit.
A war ensued, beginning with the Battle of Gonzales. A series of skirmishes followed. Early Texan successes were trumped by later crushing defeats, including the horrendous slaughter at the Alamo.
Santa Anna himself commanded the Mexican troops. Texas troops were led by Stephen F. Austin and Sam Houston. These two men would meet again after the Battle of San Jacinto, which was a surprising Texan victory against a superior Mexican force. Santa Anna was wounded in this battle, which resulted in the annihilation of his army. Houston forced Santa Anna to sign the Treaties of Velasco, in which Mexico recognized Texas as an independent nation.
For his efforts, Houston was named the first President of the Republic of Texas. Santa Anna, meanwhile, was released and, after a stay in the U.S., returned to Mexico and got himself re-elected as president.
Texas grew as a republic, and pressure grew on the United States to annex the new republic. But the republic and the nation couldn't agree on important issues, like the United States's taking responsibility for Texas's debts (as the U.S. had done after the Revolutionary War). Relations with Mexico deteriorated at the same time. As a result, when both the republic and the country agreed on final terms and the U.S. voted to annex Texas in 1844, the result was a call to arms that resulted in the Mexican-American War.