A teenager has denied posting a grossly offensive message on Facebook about the deaths in Afghanistan of six British soldiers whose bodies are due to return to the UK on Tuesday.

Azhar Ahmed, 19, appeared briefly at Dewsbury magistrates court in West Yorkshire, which was guarded by a heavy police presence as some 40 far-right demonstrators shouted abuse outside.

A racially aggravated public order charge was withdrawn and replaced with the new accusation under the 2003 Communications Act. Ahmed, from Ravensthorpe near Dewsbury, was bailed to an undisclosed address after entering his denial and confirming his name and address.

He will stand trail at Huddersfield magistrates court on 3 July.

The tragedy in Afghanistan involved soldiers of the Yorkshire Regiment, which draws many of its recruits from West Yorkshire and has its historic base at Halifax, near Dewsbury.

The soldiers died shortly after arriving for a tour of duty in Helmand province when their Warrior armoured vehicle was hit by an improvised explosive device in Lashkar Gah on 6 March. It was the worst loss of life for British forces since 14 servicemen were killed in the RAF Nimrod explosion in 2006.

This being The Guardian, the protesters, who want some reciprocity in the application of hate speech laws, are “right wing,” though their opposite numbers are never ‘left wing.’ Yes, we think it’s overkill, but these are the rules the left has made. Let them abide by them.