Maybe it’s the Viking heritage. There is an icy open-air pool in the waters of Copenhagen’s harbour, and although it is mid-winter Danes still jump in every day. On the front cover of the city’s health plan, a lean older man is pictured climbing out, dripping, his mouth open in a shout that could be horror or pleasure. “Enjoy life, Copenhageners,” urges the caption.

It’s not every Copenhagener who wants to take strenuous exercise in cold water either for fun or to get fit. But the packed bike lanes of the Danish capital, even at this sometimes subzero time of year, are testimony to the success of a city that is aspiring to be one of the healthiest in the world. Copenhagen consistently sits at the very top of the UN’s happiness index and is one of the star performers in the Healthy Cities initiative of the World Health Organisation, which, almost unknown and unsung, celebrates its 30th anniversary this year. The initiative was the idea of a group of individuals inspired by the Alma Ata Declaration of 1978, which was about elevating the status of primary care and public health in a world where everybody equated healthcare with hospital treatment after you got ill.

Cities do, of course, spawn in response to the need for people to have roofs over their heads; somewhere to eat and sleep within striking distance of their job. Whether it’s the slums of Nairobi or the skyscrapers of Tokyo, the imperative has always been to pack in more people where their talents or labour are needed. Their health, closely related to the environment in which they live, has never really figured. Only recently have we realised the ills we are reaping.

Some of our cities have notorious food deserts, with acres of housing and only takeaways and small grocery stores selling tinned and packaged foods, sugary buns, sweets, crisps and colas. It is hard to get an apple, but not a burger or chips. Green lungs – parks and gardens – are a historic feature of London, but some cities are barely walkable because of the traffic fumes, while cycling is dangerous on roads shared with juggernauts.

Obesity and its related ills – heart disease, diabetes and cancer – have thrived in these cities. Only recently have we begun to realise that fundamental social and cultural change will be needed to alter their relentless upward trajectory. City mayors have the power to kickstart this, as Michael Bloomberg showed in his high-profile interventions while mayor of New York. He cut greenhouse gas emissions and planted trees, and although he lost in court when he tried to ban sales of super-sized super-sugary soft drinks in 2012, the attempt certainly got people talking.

A mother and her child using a cargo bike; a quarter of Copenhagen families own one. Photograph: mura/Getty Images

Copenhagen is a model for how healthy cities might be created across the world. It joined the WHO Healthy Cities initiative in 1987, a year after the original 11 cities – Barcelona, Bloomsbury/Camden, Bremen, Düsseldorf, Horsens, Liverpool, Pécs, Rennes, Sofia, Stockholm and Turku. There are 1,400 cities in the scheme now. It’s not just about walkable streets, but about forging healthy, sociable, happier communities. Turku, in Finland, offers people on benefits a cut-price golden ticket: for €39 (£35) they can have six months’ access to sporting facilities, theatre seats and concerts. Newcastle has launched dementia-friendly cinema sessions. Vienna has joint exercise classes for preschool children and older people.

Copenhagen has “a very, very good health policy” to last 10 years, side-stepping the vicissitudes of political life, says Katrine Schjønning, the city’s head of public health. “We said it’s for 10 years because to make changes in public health you need a long perspective.” And they made it simple, with just six initiatives.

Promoting health in everyday life is the first, says the city’s plan, “by making it attractive to cycle, by serving nutritious lunches in our institutions or by enabling educational institutions to offer quit-smoking programmes. Healthy thriving people are … more likely to complete an education and find employment. In other words, health enables us to live the life we want.”

On the wintry Copenhagen streets, children, young adults and older people are all on bikes, with parents and their children on cargo bikes (a quarter of families in Copenhagen own one). It may look as though Copenhageners crave the outdoors, get a kick out of exercise, want to be fit and healthy, but no. It’s none of the above, say the city authorities. It’s just the easiest way to get anywhere.

“We bike all the time. We bike to the moon several times a year in Copenhagen,” says Schjønning. An extraordinary 62% of people living in the city cycle to work every day and the vast majority keep it up through cold and wet weather. “It’s not because it’s the healthy choice. It’s because it’s the easiest choice,” says Schjønning. “The city is designed for bikes and not cars.”

Meik Wiking concurs. The chief exec of the Happiness Research Institute wants to walk around the lakes in central Copenhagen as we talk about the links between health and happiness. He diverts for a few metres down a main street. “What I wanted to show you is over there,” he says, gesticulating to the far side and what looks like a drunken green bin, tilted towards the road at an angle. It’s for cyclists. “Everybody likes to cycle or walk with coffee,” he says. “Now they’ve designed it so it is easy for cyclists to throw their garbage when they are done.” At the edge of the cycle lane, where bikes have to stop for a red light, is a raised platform where riders can rest their foot without getting off the saddle. When it snows, the city clears the bike lanes before it clears the car routes.

Small things, but significant, says Wiking. “Copenhagen is not a great city in terms of monuments or attractions, but I think it’s a great city in terms of convenience, and it is a people-centred city.”

Copenhagen has hit on a truth. We don’t do what we ought to do for our health – we do what we enjoy or what makes our lives easiest. The drop-out rate after the New Year surge in gym memberships is surely clear evidence of that.

Danes, as it happens, do not seem to like being told what to do. Schjønning pulls a face when I ask about laws banning smoking in public places. There is a ban on indoor and workplace smoking, but with exceptions – for bars below a certain size, for instance. Some bars have adjusted their floor space to make sure they are small enough for smoking to be permitted. Copenhagen offers smoking cessation courses to anyone who comes to a health clinic, but the health authority can’t take a hard line on those who smoke in a children’s playground. There are notices that politely ask you not to smoke, but no penalty.

“Across the political spectrum in Denmark, banning smoking is very politicised. It has become almost a human right to smoke,” says Schjønning. “It is very black and white that the state should not tell you whether or not to smoke. The same goes for alcohol, which is really entrenched in the culture in Denmark. Young people in Denmark hold the European record for drinking. It is very difficult to limit it [smoking] because it is your personal freedom,” she says, with mock emphasis, “no matter how much the public health academics and professionals can demonstrate that smoking is the biggest killer known.”

About 62% of Copenhageners cycle, but the city is also easily walkable. Photograph: Alamy Stock Photo

Taxation has also proved tricky. There are still burnt fingers from the brief introduction of a fat tax, which hit Danish bacon and butter, but also healthy almonds and other nuts, says Schjønning. The tax was dumped in 2012, along with plans for one on sugary drinks. Nobody had accounted for shoppers’ determination to save money.

“The problem we have – because we’re not an island like England – is that people travel across the border to Germany and then they will buy soft drinks, tobacco and alcohol. It’s bad for public health and it’s very bad for finances and the tax.” So Copenhagen shrugs its shoulders and doesn’t do prohibitions or tax or hector its citizens. It takes the subtler route of making the road to health the obvious one to travel. It is developing a city where it is harder not to be healthy and environmentally friendly, with reduced air pollution thanks to initiatives such as the “green roofs”. As part of its determination to become carbon-neutral by 2025, Copenhagen requires all new flat roofs to be planted with vegetation.

Other initiatives include equal attention to mental and physical health and partnering with day-care facilities, schools, workplaces and others to embed healthy lifestyles. But the hardest is tackling the inequalities that exist in Copenhagen, as in any city. Crossing Queen Louisa’s Bridge across the lakes, from the city centre to the multicultural, hip but poorer district of Nørrebro, the average man’s life expectancy drops by seven years.

“People who will live longest are the people with the most education. You see it not in income but in educational level. It is really, really clear,” says Schjønning. Those most in need are the hardest to reach. They are likely to be the chronic smokers and drinkers and those whose difficult lives result in mental health problems. “We have many people who suffer from stress and depression and anxiety,” says Sisse Marie Welling, the 31-year-old mayor for health and older people, when we meet in City Hall, its imposing rooms and staircases familiar from the TV series The Killing and Borgen.

Mental ill-health, says Welling, is a big problem in the western world. “We must be doing something wrong to make so many people suffer from mental health issues. Right now, we are trying to make it free to get the help you need,” she says. In Denmark, although medical treatment is free, people have to pay a contribution towards the cost of mental healthcare.

So Copenhagen is offering free stress clinics for anyone who needs them. Not just for people who are working too hard, but also those who are stressed because they don’t have a job or because of other problems. Referral must come from a GP and, so far, it tends to be 30- to 40-year-old women coming forward. With the health inequality gap very much in mind, the plan is to advertise in job centres to try to reach the reluctant, unemployed 50-year-old men from lower socio-economic groups.

With a 37-hour working week, Denmark is more enlightened than most countries. Many people go home early to pick up the children, even if they then work on in the evening at home. Childcare is generously subsidised by the government for most parents, and free for those on the lowest incomes, so almost all mothers of younger children work. “I think it is better than in other countries, but everybody is in the workforce in Denmark,” says Welling. That presents its own stresses, she admits. She has a seven-month-old baby. “You have to have time with your child,” she says. And the families with young children tend to be those where both parents are working hard to pay for a house.

“Most of the stress is that you are never off work. Your employer is paying for your mobile phone and can call you at night. And then we have higher ambitions. We want to be the best parents, the best people in our own lives and we have higher expectations. Society makes us impose the stress on ourselves,” she says.

Enjoying a relaxing picnic at Bellevue beach, at Klampenborg, just outside the city. Photograph: Adrian Lazar/Getty Images

Copenhagen launched its stress clinics after a survey showed that 23% of its residents felt stressed a lot of the time. The nine-week course focuses on group discussions of shared problems and solutions and mindfulness training. Those who come can also get subsidised yoga and other classes, and they are encouraged to keep in touch with their group afterwards. It has been a big success, with almost a 30% drop in the symptoms of those attending.

Surveys throw up contradictory findings all the time. Although nearly a quarter of Copenhageners say they are stressed, the city still sits at the top of that UN happiness index.

This may be to do with the reflective nature of the question. Wiking explains that it is intended to measure what he calls the cognitive dimension of happiness, not how you feel right now. “It’s where you essentially take a step back and evaluate your life,” he says. So the question being used is: imagine the best possible life you could lead and the worst possible life you could lead on a scale from 10 to zero. Where do you stand on that?”

The answer, for Danes, is 7.57. That is an average over the years 2013-17. Switzerland is a close second and Norway third. Other Scandinavian countries come not far behind. The UK is 24th, scoring 6.79, below Australia, the US and Ireland, as well as Costa Rica, Puerto Rico, Mexico, Oman and the United Arab Emirates.

Copenhagen comes first in a country where people can pay as much as 60% of their income in taxes. Wiking believes that may be part of the reason. The Nordic countries, he says, “have simply been better at converting wealth into wellbeing. We invest in quality of life. Yes, if I paid lower taxes I could afford a bigger car, but that’s not going to bring me happiness. What brings me happiness is knowing that everybody I love and care for is taken care of. That’s the key to understanding Scandinavian happiness. In a sense, I feel the Scandinavian model has removed the price tag on happiness.”

In this highly taxed society, education – from daycare for babies, to university – is free, and students get a very generous monthly grant to go with it. Hospital treatment is free and the municipalities such as Copenhagen get heavily fined for every day that an older person stays in a hospital ward when they could go home, so bed-blocking is out of the question. Daily care for the elderly at home is also free. It is, says Welling, a young city, so has not yet had to deal with the scale of an expanding elderly population that the NHS struggles to support.

That may come. Copenhageners used to move out of the city when they retired. Now they are increasingly choosing to stay with their families and enjoy the city. Property prices are rising as a result and the economic, social and health gap between the better and worse off is widening, as in so many countries. Somehow, though, you can’t help thinking Copenhagen will manage it much better than most.

• This article was amended on 13 February 2018. An earlier version suggested childcare in Denmark is “free for all”.