The ban will cover food high in sugar, salt and fat, with products affected including chocolate, soft drinks, cakes, sweets, ice cream, biscuits, sweetened juices, crisps, chips and pizzas.
The restrictions will be UK-wide.
Fast food and confectionery giants will be banned from advertising products high in fat, sugar and salt (HFSS) online, but there will be exemptions for small businesses with 249 employees or fewer.
Restrictions will stop short of the total ban that was proposed last year, part of Boris Johnson’s efforts to tackle obesity, as brand-only advertising online and on TV will be allowed to continue.
Companies can continue to promote their products on their own websites and social media platforms under the new measures.
Firms will also be able to advertise on television before the watershed if they do not show banned foods – a ruling that is expected to be opposed by health campaigners.
Online audio will be exempted, meaning that fast food and confectionery will be advertised on radio stations broadcasting over the internet, as well as on podcasts.
The new regulations also allow exemptions for the healthiest foods within each category, such as honey, olive oil, avocados and marmite.
Public health minister Jo Churchill said: “We are committed to improving the health of our children and tackling obesity. The content youngsters see can have an impact on the choices they make and habits they form. With children spending more time online it is vital we act to protect them from unhealthy advertising.
“These measures form another key part of our strategy to get the nation fitter and healthier by giving them the chance to make more informed decisions when it comes to food.
"We need to take urgent action to level up health inequalities. This action on advertising will help to wipe billions off the national calorie count and give our children a fair chance of a healthy lifestyle.”
Research has found one in three children leaving primary school are overweight or obese.
The consultation cited research finding children were being exposed to increasing online junk food advertising. The UK Government estimated children aged under 16 were exposed to 15 billion junk food adverts online in 2019, compared with an estimated 700 million two years earlier.
Caroline Cerny, from the Obesity Health Alliance, said: “Going ahead with landmark policies to restrict unhealthy food advertising shows that the government is serious about putting our nation’s health first.
“Tough new restrictions will stem the flood of adverts on TV and online that entice us towards sugary and high fat foods, making space to advertise healthier foods.”
Barbara Crowther, Sustain’s children’s food campaign co-ordinator, said: “The proposals represent a significant step forward in reducing exposure to a constant stream of unhealthy food and drink advertising on TV and online.
"The government has been subjected to intense industry lobbying to keep advertising junk food everywhere, and we’re delighted that they have resisted this pressure and are standing up for children’s health and a healthier food environment for all.
“However, we remain concerned that the proposals will still allow massive multinational junk food companies and delivery platforms to run big brand campaigns. In short, it’s a very positive step in the right direction, but the journey towards a comprehensive healthier food advertising world is far from over.”
The UK population's weight has risen since the early 1990s, with more than 60 per cent of the adult population now overweight or obese, according to NHS Digital.
Commenting on the plans for restricting the marketing of high fat, sugar and salt foods, Dr Charmaine Griffiths, chief executive of the British Heart Foundation, said: “Introducing a 9pm TV watershed for junk food adverts and also further restrictions for online advertising is one important part in building a more healthy environment where the healthy option is the easy option.
"Sadly, children with obesity are more likely to grow up to be adults with obesity, putting them at greater risk of serious illness such as heart attack or stroke – so pressing ahead with strong measures now will help save lives in the years to come.”
The Advertising Association said it was “dismayed” by the ban and the food and drink sector branded the plans “headline-chasing policies”.
Sue Eustace, public affairs director at the Advertising Association, said: “We are dismayed government is moving ahead with its HFSS ad ban on TV before the 9pm watershed and increased restrictions online.
“This means many food and drink companies won’t be able to advertise new product innovations and reformulations and larger food-on-the-go, pub and restaurant chains may not be able to tell their customers about their menus. Content providers – online publishers and broadcasters – will lose vital advertising revenue to fund jobs in editorial and programme-making.
“We all want to see a healthier, more active population, but the Government’s own analysis shows these measures won’t work. Levelling up society will not be achieved by punishing some of the UK’s most successful industries for minimal effect on obesity levels.”
The Food and Drink Federation’s chief scientific officer, Kate Halliwell, said: “We are disappointed that the government continues to press ahead with headline-chasing policies, which will undermine existing government policies, principally the reformulation programmes to reduce calories, sugars and salt and portion sizes.
“The proposals would make it difficult to advertise many products that have been carefully reformulated or created in smaller portions in line with the government’s own targets; for example, Cadbury would not be able to advertise their 30 per cent reduced sugar Dairy Milk.”
“Not only do the proposals signal a lack of joined-up policy, the implementation periods for both advertising and promotional restrictions do not give businesses enough time to prepare for the changes.”