CityLab has a good take on how the Democratic Party became the party of cities in the US:
The story begins in the late 19th century, in the filthy, sweaty maw of the Industrial Revolution. To reduce transportation costs, industrialists had built factories in cities with easy access to ports. These factories attracted workers by the thousands, who piled into nearby tenements. Their work was backbreaking—and so were their often-collapsing apartment buildings. When urban workers revolted against their exploitative and dangerous working conditions, they formed the beginning of an international labor movement that would eventually make cities the epicenter of leftist politics.
While workers’ parties won seats in parliamentary European countries with proportional representation, they struggled to gain power in the U.S. Why didn’t socialism take off in America? It’s the question that launched a thousand political-economy papers. One answer is that the U.S. political system is dominated by two parties competing in winner-take-all districts, making it almost impossible for third parties to break through at the national level. To gain power, the U.S. labor movement had to find a home in one of those parties.
This set up the first major inflection point. America’s socialists found welcoming accommodations in the political machines that sprouted up in the largest manufacturing hubs, such as Chicago, Boston, and New York. Not all of the “bosses” at the helm of these machines were Democrats; Philadelphia and Chicago were intermittently controlled by Republicans. But the nation’s most famous machine, New York’s Tammany Hall, was solidly Democratic. As that city’s urban manufacturing workforce exploded in the early 20th century, Tammany Hall bosses had little choice but to forge an alliance with the workers’ parties.
Of course, the more axes on which the parties differ, the less tolerant they become. The cycle of polarization continues.