During the eighteenth century (in England) and the nineteenth century (in other Western European nations and in the United States and Canada), industrialism overtook agriculture as the main source of a modern society's wealth. When most wealth came from farming and when aristocrats, the owners of huge tracts of land, were in charge, most of a country's population resided in rural areas. This was necessary so that people could work in the fields.
As factory-produced goods became the center of wealth, more and more people were needed to work in the factories. This led people to migrate to cities and areas around factories in search of work. Because of this, existing cities saw great increases in population and new urban centers arose around factories. Rural areas depopulated, and urban areas became much more densely packed.
Although work in factories was often brutal in the early days of industrialism, factories raised the overall standard of living by lowering the cost of basic goods, such as clothing. People therefore lived longer, and this added to population pressures. In the United States and Canada, waves of immigration due to famine, persecution, and the desire for a better life in the industrial period also lead to exploding populations in urban areas, all of which fed the growing industrial machine.
However, these cities with suddenly large populations could not be called "modern," as they lacked basic sanitation, building codes, food inspection, adequate police forces, and other amenities. Over time, the diseases and other problems caused by packing people densely together without any attention paid to urban planning led to the regulated and cleaner cities we know today.