Edinburgh took delivery of its first tram this year and work on constructing its new tramway system is under way at a pace after delays and cost over-runs. Trams have been around a lot longer than many people realise. Their 200-year-old history is traced by BBC Four's Timeshift.

The world's first passenger tram originated in Wales. In 1807 the Mumbles to Swansea service was launched. The wagon was completely open but running it on rails meant a much smoother ride for passengers than on a horse bus, which ran over bumpy roads and potholes.

It was not until 1860 that horse-drawn trams started appearing in Britain's major cities. Birkenhead established the first route, from Woodside to Birkenhead Park. The following year London's first tramway opened between Marble Arch and Notting Hill Gate. The service was later withdrawn due to local opposition.

By the late 1800s there were thousands of horses on the roads and towns and cities began to smell like farmyards. Each horse deposited 30lb (14kg) of manure a day and two gallons (9 litres) of urine. Horse manure was being linked to infant mortality. The hunt was on for a new kind of traction.

A steam-powered tram arrived in 1885 but had a limited lifespan. People were terrified of the noise and feared they would explode. When passengers boarded dressed in white, they very often later got off dressed in black.

The world's first electric tram was tested at Lichterfelde near Berlin, Germany, in 1881. Within four years Britain got its first electric tramway in Blackpool, with the car picking up the current from a third middle rail in the road. This later changed to an overhead wire which was safer and more reliable.

By the 1920s trams were enjoying a golden era. Britain's towns and cities had vast networks and lower fares meant the tram became the main transport of the working classes. Trams were now much more comfortable, with enclosed top decks.

Trams are regarded with warm affection by many - not least the comedian Ken Dodd, who tells of his joy at having a tram route running past his home in Knotty Ash. "When I was a Diddyman, we went everywhere by tram," he recalls.

Many tram systems were left battle-scarred in World War II, with bombs closing lines and depots. After the war it made economic sense to dig the tracks up rather than re-lay them.

In the post-war years, the major cities closed their tramways. Manchester closed its service in 1949. The last tram ran in London in 1952. Glasgow was the last major UK city to have a tram system and that closed in 1962.

Between 1962 and 1992, Blackpool was the only town in Britain to operate a municipal tramway, with 10 miles of track running from Stargate on Blackpool's south shore to Fleetwood. Brightly lit trams disguised as steam engines, rockets or boats were brought out during the Blackpool illuminations.

By the 1980s traffic congestion was becoming a major problem in Britain's cities and planners began to turn to trams or light railways as a solution. Manchester opened its new tramway in 1992 and other schemes followed in Sheffield, Croydon and Birmingham.