Mr Starmer had previously published draft guidelines in the wake of concerns around decisions to prosecute social media users.
In 2010 Paul Chambers was prosecuted for jokingly Tweeting about blowing up Robin Hood airport. His conviction was subsequently overturned.
Mr Starmer said he had “aimed to strike the right balance between freedom of expression and the need to uphold the criminal law” in drawing up both the draft and final guidelines.
He said a consultation on the draft guidelines had found “wide support” for that approach.
Starmer added: “Having considered the consultation responses, and our experience of dealing with these cases in recent months, I believe the guidelines do set out the right approach to prosecution by making the distinction between those communications that should be robustly prosecuted, such as those that amount to a credible threat of violence, a targeted campaign of harassment against an individual or which breach court orders, and those communications which may be considered grossly offensive, to which the high threshold must apply.
“These are cases that can give rise to complex issues, but to avoid the potential chilling effect that might arise from high numbers of prosecutions in cases in which a communication might be considered grossly offensive, we must recognise the fundamental right to freedom of expression and only proceed with prosecution when a communication is more than offensive, shocking or disturbing, even if distasteful or painful to those subjected to it.”
Starmer said the new rules would “help prosecutors to make fair and consistent decisions to prosecute in those cases that clearly require robust prosecution in accordance with the Code for Crown Prosecutors, and to uphold the right to freedom of speech in those cases where a communication might be considered grossly offensive, but the high threshold for prosecution is not met.”