The Mayor of Casterbridge is set in the fictional town of Casterbridge in the imaginary county of Wessex, an area in the south of England in which Hardy locates most of his realist fiction. "Casterbridge" is based on the town of Dorsetshire, a real place in the county of Dorset where Hardy himself grew up. Wessex as a delineated area actually used to exist in ancient Britain, and Hardy invokes ideas of longevity and a strong relationship to English history by reclaiming this space for his writing. The action of the novel occurs somewhere around the late 1840s, and Hardy based many of the social concerns of the book, such as food shortages and income inequality, on real events happening in his own lifetime.
The rural and idyllic landscapes of Southern England, with their “rich” fields of grain and their lush green expanses contrast with harsh and industrialized environments in The Mayor of Casterbridge. This makes the “past” (an idealized version of unspoiled countryside) seem appealing and the “present” (rapidly modernizing and industrializing England) seem unwelcoming. At times, however, the novel reverses or revises these alignments, as Hardy himself was not opposed to social change.
The novel also references distant overseas locations like Canada, to and from which characters return suddenly and to dramatic effect. Victorian Britain was a country caught up in the swell of rapid globalization, and lots of Hardy’s books contain sea voyages to and from far-flung locations. As it is what is commonly referred to as a "social novel," or one that is concerned with the particulars of interpersonal interactions in communities, a lot of the action of this book takes place in the interiors of houses, inns, and municipal buildings. Both the “wider world” and the smaller world of homes and offices are depicted with specificity and attention.