Zach’s Law is named after 12-year-old Zach Eagling who was the victim of an online attack when he was targeted by bullies while doing a sponsored walk for the Epilepsy Society.
The Royal Assent was passed by King Charles on October 26.
Under the legislation, social media companies will be more responsible for keeping users safe.
Technology secretary Michelle Donelan said: “At the heart of this bill is the protection of children. I would like to thank the campaigners, parliamentarians, survivors of abuse and charities that have worked tirelessly, not only to get this act over the finishing line, but to ensure that it will make the UK the safest place to be online in the world.”
If social media platforms do not comply with the new legislation, Ofcom could fine them up to £18 million or 10% of their global annual revenue, whichever is biggest.
Zach’s mum Claire Keer said: “When Zach was first attacked on Twitter by internet trolls sending flashing images to try to trigger a seizure, I could not believe how mindless and malicious people could be.
“But my faith in humanity has been completely restored by the unfailing support we have received. I’ve been so proud of Zach as figurehead of the Epilepsy Society’s campaign to make the law on this barbaric behaviour fit for the 21st century.”
Epilepsy Action’s senior policy and campaigns manager Daniel Jennings said: “It’s encouraging to see legislation being amended to specifically protect people with epilepsy, and that deliberately trying to trigger a seizure online will now be treated as a criminal offence.
“People with epilepsy deserve to feel safe online, and not have to fear being targeted by people intentionally trying to provoke a seizure. We celebrate Zach’s courage and perseverance in continuing with his campaign to help other people with epilepsy.”