Before the 18th century the Taipei Basin, an ancient lakebed, was the land of the Ketagalan, a Plains Indigenous people. Han Chinese settlers from southern Fujian began moving in from 1709. The river towns of Bangka and Twatutia then prospered on overseas trade, tea above all. You can still see the settlers' building style in old Dadaocheng, where the Xia Hai City God Temple is built like the temples of southern Fujian.
The city itself was planned from above. In 1875 the Qing created a new Taipeh Prefecture and put its seat, Chengnei or "the inner city", between the trading towns; by the end of 1879 its gates were almost finished, paid for in large part by the wealthy Lin family of Banqiao. Governor Liu Mingchuan moved the capital here in 1884, and in 1887, with Taiwan newly made a province, the city became its capital. He walled the city, paved its streets with stone, tried electric street lighting and began a railway to Keelung, the first in China.
Little of that Qing city survives. Japan took Taiwan in 1895, renamed the capital Taihoku and tore down the walls and West Gate for roads and railway lines. Later the Kuomintang rebuilt three of the remaining gates in northern palace style, so only the North Gate keeps its Qing form. An elevated freeway hid it for years; that came down in 2016, and the gate now stands in its own park.
Japanese rule shaped the government quarter you walk through today. The Presidential Office Building in Zhongzheng was the Governor-General's office, and the National Taiwan Museum, the island's oldest, was founded in 1908. In less than a decade after the handover, the city had lost its Chinese look. Allied planes bombed it several times, worst of all on 31 May 1945.
After Japan's surrender in 1945 the Kuomintang took control. The 28 February Incident of 1947 began in Taipei and turned into an island-wide crackdown by Chiang Kai-shek's forces, followed by martial law; 228 Peace Park and its memorial museum remember it. On 7 December 1949, beaten by the Communists on the mainland, Chiang made Taipei the provisional capital of the Republic of China. Refugees crowded into makeshift housing, later replaced by the plain concrete apartment blocks still seen across town. They also brought their regional cooking, which is why you can eat so well from every corner of China here.
Then it grew. Taipei passed a million people in the early 1960s, became a special municipality in 1967 and a year later absorbed Shilin, Beitou, Neihu, Nangang, Jingmei and Muzha, which multiplied its area by four. That is why the hot spring valley of Beitou and the tea hills of Muzha sit inside the city limits. By the mid-1970s it had over two million people, and from the 1980s an economic boom brought tree-lined boulevards, cafés and better apartments.
Taipei also led Taiwan into democracy. In 1990 the Wild Lily student rallies packed the square in front of Chiang Kai-shek's memorial, and by 1996 one-party rule had given way to multi-party elections. Meanwhile the money moved east. Xinyi, once part of the village of Matsuyama, is now the main business district, with Taipei 101 at its centre.