The trial against six young Iranians who danced in a YouTube version of Pharrell Williams' viral song Happy has started in Tehran.

The three men and three women, who have an average age of 25, were arrested in May, as police accused them of helping make an "obscene video clip that offended the public morals" and later released on bail.

The arrests triggered an international outcry and were condemned, among others, by Pharrell, whose hit was downloaded millions of times in the US and danced by people all over the world.

"It is beyond sad that these kids were arrested for trying to spread happiness," the singer wrote on his Facebook page.

The six friends are facing a series of charges including having sex outside marriage, posting on "the vulgar YouTube channel", failing to observe proper Islamic dress, dancing, and having contacts with contact with foreign television networks, an allegation that could entail the more serious offence of spying, The Times reported.

Under Islamic law women must cover themselves from head to toe and even though there were hopes of a liberalisation in laws following last year's election of president Hassan Rohani, the internet is still heavily filtered with access to popular social networking sites prohibited in Iran.

The case has however underscored frictions between reformists and conservatives within the regime.

Rohani himself contradicted authorities taking to the defence of the six dancing friends with a surprise tweet: