Gunman kills at least five in one of deadliest recorded attacks on US media.

Five people were killed and two others injured after a gunman opened fire in the newsroom of a Maryland newspaper in one of the deadliest recorded attacks on a US media outlet.

The attacker walked into the office of Capital Gazette on Thursday afternoon with smoke grenades and a shotgun in what police called a “targeted attack”.

“This person was prepared to shoot people. His intent was to cause harm,” acting police chief of the Anne Arundel County Police Department William Krampf told a news conference.

Among the dead were four journalists and one staffer.

Jarrod Ramos, 38, was taken into custody and charged with five counts of first-degree murder. He had a long-running feud with The Capital newspaper and had sued journalists there for defamation.

Capital Gazette reporter Phil Davis tweeted that a “gunman shot through the glass door to the office and opened fire on multiple employees”.

“There is nothing more terrifying that hearing multiple people get shot while you’re under your desk and then hear the gunman reload,” he also said on Twitter shortly after the attack.

There is nothing more terrifying than hearing multiple people get shot while you're under your desk and then hear the gunman reload — Phil Davis (@PDavis_LLC) June 28, 2018

Davis later tweeted that he was safe and no longer at the newspaper’s office.

Those killed included Rob Hiaasen, 59, the paper’s assistant managing editor and brother of novelist Carl Hiaasen. Carl Hiaasen said he was “devastated and heartsick” at losing his brother, “one of the most gentle and funny people I’ve ever known.”

Also slain were Gerald Fischman, editorial page editor; features reporter Wendi Winters; reporter John McNamara, and sales assistant Rebecca Smith.

Ramos filed a defamation lawsuit against Capital Gazette in 2012, after an earlier article had detailed a harrasment charge to which he pleaded guilty in July 2011.

“Jarrod Ramos has a long history of being angry and taking action against The Capital newspaper,” Tom Marquardt, a former executive editor at The Capital told the New York Times.

“I said at one time to my attorneys that this was a guy that was going to come and shoot us. I was concerned on my behalf and on behalf of my staff he was going to take more than legal action.”

President Donald Trump responded to the attack via Twitter: “My thoughts and prayers are with the victims and their families. Thank you to all of the First Responders who are currently on the scene.”

Maryland Governor Larry Hogan said that he was “absolutely devastated” to hear of the tragedy.

Capital Gazette tweeted they would be putting out a newspaper on Friday.

The newspaper offices are located in a four storey building about four kilometres from the Maryland State House and the nearby US Naval Academy.