Facing potential Lords defeat, government announces it will back data protection bill amendment to safeguard children’s privacy.

Websites and apps will be subject to a tough new code of practice to protect children’s privacy online following a cross-party campaign in the House of Lords to prevent young people’s internet activity being monitored.

Facing a potential defeat by peers, the government has announced it will back a new amendment to the data protection bill, derived from one authored by the film director and cross-bench peer Beeban Kidron, which has been backed by Tories, Labour and the Lib Dems.

Lady Kidron, whose films include Bridget Jones: The Edge of Reason, said children’s data was constantly being gathered in order to bombard them with targeted advertising, risking their personal information being disseminated across the web.

She has previously highlighted how companies such as Instagram, owned by Facebook, collect and share children’s home and school addresses, track their locations and store their dates of birth, phone numbers and photos.

The digital minister Matt Hancock said his department had agreed to create a statutory process by which a code from the information commissioner’s office on age-appropriate website design could be produced.

It will set new standards of privacy on websites and apps for children under 18 which make clear what personal data is being collected, how it is being used and how children and parents can stay in control of the data.

“We strongly support freedom online, while protecting people, and particularly children, from harm,” Hancock said. “There is growing evidence on the need for this. This statutory code of practice will require tailored protections to be built into websites and apps for children under 16. This must be done in a way that protects the wonderful freedom and opportunity of the internet, without jeopardising the future free flow of data between the UK and EU.”

The government might have lost in the House of Lords had it not accepted the new protection measures, owing to strong cross-bench support for passing Kidron’s original amendment, including from the Conservative peer Dido Harding, a former chief executive of TalkTalk, who told the Guardian last month that regulation was the last option available.

“I would love to believe that commercial platforms will move fast enough that you don’t have to regulate, but there is no sign that they are,” she said.

The move has been backed by a raft of high-profile media organisations and charities including the NSPCC, the children’s commissioner for England, Sky, TalkTalk, YoungMinds and the Children’s Society.

“These amendments unequivocally establish that children are children – even online,” Kidron said. “And I hope that all of us can now continue to work to make certain that the same principle is reflected in every aspect of a child’s digital life. There is still much to do.

“It is stated on the face of the bill that the code must meet the development needs of children and that the regulator must take account of children, parents and those who advocate for children’s rights online, as well as industry. It is up to us all to make sure that the code is robust, meaningful and effective for children.”

The ICO will be given time to carry out a proper consultation on the code of practice but will be expected to present a draft code for parliamentary approval within 18 months of the day on which the data protection bill passes into law.