DPP Keir Starmer says the scale of the problem litigators are confronted with should not be underestimated.

"There are millions of messages sent by social media every day, and if only a small percentage of those millions are deemed to be offensive then there's the potential for very many cases coming before our courts," he said.

In 2010 a UK tweeter sent anti-terrorism police into a flap with a joke about blowing up Yorkshire's Robin Hood airport.

Paul Chambers' case went all the way to London's High Court before his conviction for sending a "menacing electronic communication" was quashed on the grounds that it was nothing more than a joke.

His lawyer David Allen Green says the new guidelines would have prevented the court's scant resources from being wasted.

"People are communicating with social media in a way which they never did before, so the police actually have to do something," Mr Green said.

"It took two years for us to explain to the English legal system that Paul Chambers had actually sent what was effectively a joke."

Mr Starmer said the guidelines were about striking a fine balance, but if the communication is a threat or a campaign of harassment, robust punishments stand.

He says that "the right of the individual not to be subjected to threats and harassment" has to be balanced by "the rights of others to have freedom of expression."

"If the communication is deeply unpopular, shocking, grossly offensive, but not a threat and not a campaign of harassment, then there will be a high threshold for prosecution and prosecution will be unlikely."

Victim support groups have welcomed the guidelines, saying vindictive targeting on social media can leave deep emotional and psychological scars.

The guidelines are subject to a three-month public consultation period.