Mars, the fourth planet from the Sun, has appeared as a setting in works of fiction since at least the mid-1600s. Trends in the planet's portrayal have largely been influenced by advances in planetary science. It became the most popular celestial object in fiction in the late 1800s, when it became clear that there was no life on the Moon. The predominant genre depicting Mars at the time was utopian fiction. Around the same time, the mistaken belief that there are canals on Mars emerged and made its way into fiction, popularized by Percival Lowell's speculations of an ancient civilization having constructed them. The War of the Worlds, H. G. Wells's novel about an alien invasion of Earth by sinister Martians, was published in 1897 and went on to have a major influence on the science fiction genre.
Life on Mars appeared frequently in fiction throughout the first half of the 1900s. Apart from enlightened as in the utopian works from the turn of the century, or evil as in the works inspired by Wells, intelligent and human-like Martians began to be depicted as decadent, a portrayal that was popularized by Edgar Rice Burroughs in the Barsoom series and adopted by Leigh Brackett among others. More exotic lifeforms appeared in stories like Stanley G. Weinbaum's "A Martian Odyssey".
The theme of colonizing Mars replaced stories about native inhabitants of the planet in the second half of the 1900s following emerging evidence of the planet being inhospitable to life, eventually confirmed by data from Mars exploration probes. A significant minority of works persisted in portraying Mars in a nostalgic way that was by then scientifically outdated, including Ray Bradbury's The Martian Chronicles.
Terraforming Mars to enable human habitation has been another major theme, especially in the final quarter of the century, the most prominent example being Kim Stanley Robinson's Mars trilogy. Stories of the first human mission to Mars appeared throughout the 1990s in response to the Space Exploration Initiative, and near-future exploration and settlement became increasingly common themes following the launches of other Mars exploration probes in the latter half of the decade. In the year 2000, science fiction scholar Gary Westfahl estimated the total number of works of fiction dealing with Mars up to that point to exceed five thousand, and the planet has continued to make frequent appearances across several genres and forms of media since. In contrast, the moons of Mars—Phobos and Deimos—have made only sporadic appearances in fiction.