A teenager accused of making a pipe bomb in preparation for an "all-out race war" celebrated the killing of MP Jo Cox on the day she died, praising her murderer as a hero, a court has heard.

Police found a device in a desk drawer in the 17-year-old's Bradford bedroom after they were alerted through his Snapchat messages, prosecutors told Leeds Crown Court.

One of these messages was a cartoon-like image of a mosque being blown up along with the words: "It's time to enact retribution upon the Muslim filth."

Another was a picture of a pipe bomb with an image of the Bradford skyline and the message: "Incendiary explosive and home-made black powder. More to come."

A jury heard how officers found the defendant's bedroom covered in flags, including the Swastika and the symbol of the Waffen SS as well as a laptop with wallpaper featuring a Nazi eagle over a Swastika and the German phrase: "One Nation, One Empire, One Leader".

Barnaby Jameson, prosecuting, said that on the day Mrs Cox was killed by Thomas Mair in her Batley and Spen constituency on June 16 last year, the defendant posted a picture of Mair on Facebook.

He also posted the message: "Tommy Mair is a HERO. There's one less race traitor in Britain thanks to this man."

Shortly after, on another social media site, the defendant posted the same picture with the post: "Absolute f****** legend. He's a hero, we need more people like him to butcher the race traitors."

The prosecutor said: "(The teenager's) political views were so extreme that he celebrated in the murder of a democratically elected MP - presumably because she had voted to remain in the EU. In (the defendant's) view this was race treachery."

The judge, Mr Justice Goss, reminded the court that Mrs Cox's murder happened before the EU Referendum.

Mr Jameson took the jury through a number of social media postings and messages detailing what he said was the defendant's racist, white-supremacist views.

Many of these related to his links with National Action, which the prosecutor described as "a small, secretive Neo-Nazi British youth nationalist organisation."

He said: "Little is known about its internal structure or the size of its membership. It is known to be a white supremacist group.

"At public meetings, members make the Nazi salute and keep their faces covered."

Mr Jameson said messages from members of a National Action chat group found on the defendant's phone included phrases like "should we just blow up Leeds or some s***?"

During one message exchange, the defendant said: "'I don't use cookers, but I make miniature pipe bombs and s***. Just f*** around with them'."

Mr Jameson told the jury: "As we will hear in due course, (the defendant) did something with a pipe bomb that was less to do with 'f***** around with them' and more to do with an ideological war he was waging."

After he was arrested, the teenager told police he had made the pipe bomb out of sparklers, the prosecutor said.

The teenager said in a statement when interviewed: "I've simply been fooling around with fireworks and showing them off to my peers in my naivety I have never had the intention to cause any harm to any person."

Mr Jameson said the pipe bomb was tested and was "a viable device - technically known as an Improvised Explosive Device or 'IED'."

Summarising the case to the jury of six men and six women, the prosecutor said the incident "places (the defendant) squarely in the terrorism legislation as a man with a political and racial and ideological cause".

He said: "This was not, as the defence will suggest, a bad joke gone wrong. This was the opening stage of (the defendant's) all-out race war and that is why the crown leads it case with an allegation under the terrorism legislation."

The blond-haired teenager, who cannot be named, denies a charge of preparing a terrorist act and an alternative count of making a pipe bomb.

He sat in the dock wearing a suit and flanked by a security guard.

The trial was adjourned until Wednesday.