The Scottish government's decision not to allow older pupils to opt themselves out of religious observance is facing a legal challenge.

The Humanist Society of Scotland (HSS) is seeking a judicial review of the policy.

Earlier this year a United Nations committee called for a change to the guidelines in Scotland.

The government said schools were encouraged to discuss options with parents and children.

It added that religious observance should be sensitive to individual beliefs - including those who have none.

Compulsory attendance

All school pupils in Scotland need parental permission to withdraw from religious activities like assemblies.

But sixth form students in England and Wales, normally aged between 16 and 18, have the right to make their own decision about opting out.

Gordon MacRae, the chief executive of the HSS, said: "Today in Scotland young people are trusted to get married, join the army and vote in elections and for the constitutional future of Scotland.

"However, Scottish ministers still do not trust them to make their own decisions about attending religious observance or to give young people the same rights as those living in England and Wales."

Religious observance must take place in Scottish schools at least six times a year.

In June, a report by the UN committee on the rights of the child highlighted the fact that children in Scotland are not able to legally withdraw from religious observance.

It recommended that laws requiring compulsory attendance at religious worship are scrapped.

However, the Scottish government ruled out a review of the policy.

Now the humanist group have submitted papers to the Court of Session. It believes the government may have acted unlawfully by refusing to ensure their guidance remains in line with international humans rights law.

'Outdated requirement'

Mr MacRae said: "For some time now, Humanist Society Scotland has been calling on the Scottish government to update its policy on religious observance.

"I had hoped that if they would not listen to us then at least they would listen to the United Nations children's rights committee.

"We have worked with a number of organisations and individuals over the years to seek to reform religious observance, most notably the Church of Scotland in 2014, with whom we issued a joint call for reform.

"Sadly our efforts to seek progressive reform of this outdated requirement of Scottish education has failed.

"The Scottish government's policy on religious observance is a mess, a classic political fudge. Our young people deserve better."

A spokeswoman for the Scottish government said: "Religious observance should be sensitive to individual beliefs, whether these come from a faith or non-faith perspective.

"Parents are legally entitled to withdraw their children from religious observance in our schools.

"While there is currently no legal basis for children to remove themselves from religious observance, the flexible approach to learning and teaching afforded by Curriculum for Excellence in Scotland encourages schools to discuss options with both parents and their children, this could also include allowing pupils to withdraw from religious observance if they wish."

The Church of Scotland said it supports the idea of a "time for reflection" in schools.

Rev Dr Richard Frazer, convener of its church and society council added: "Such moments do not seek to indoctrinate or give preference to one faith tradition but instead enable shared reflection and a deepening of our understanding of the rich range of spiritual and secular traditions held within our society".

Analysis by Jamie McIvor, BBC Scotland education correspondent

The law may not have changed since 1980 - but the common practice in non-denominational schools has changed hugely.

In the 1980s, it was still common for children in non-denominational schools to start the day with the Lord's Prayer, sing hymns and attend a church service at the end of term.

Today things are very different.

The common practice is to hold what are, in effect, times for reflection - designed to be inclusive of children from all faiths and none. They do not take the form of worship.

Schools will often have pastors representing all significant faith communities in their catchment areas.

While, for example, the local Church of Scotland minister may be a well known figure in the school and may well talk about religious themes - for instance giving a Christian perspective on an issue - they cannot proselytise.

The right of parents to withdraw their children from these activities is enshrined in law - but, of course, a child cannot make the decision to pull out.

A few years back, the Church of Scotland considered the issue of formally turning religious observance into "times of reflection" - one reason for this was that some were concerned parents might withdraw their children because they misunderstood the nature of the events.

Occasionally controversies erupt over the role of religion in non-denominational schools.

Three years ago there was a row when pro-Creationist material was distributed at a primary school in East Kilbride by members of a small American-based church which is active within the town. The headteachers were moved. Later the council toughened its rules.