Campaigners launched a judicial review in the High Court against the Welsh government's new relationships and sexuality education (RSE) curriculum.
It was launched in September and sees the mandatory teaching of these topics to pupils from the age of three.
The legal challenge was rejected but claimants plan to appeal.
It follows a two-day legal hearing in November at the Civil Justice Centre in Cardiff.
The claimants were five parents of children of school age living in Wales who objected on religious and or philosophical grounds to their children being taught the subjects.
Mrs Justice Steyn said: "Teaching should be neutral from a religious perspective, but it is not required to be value neutral."
It referenced sex education that aims to encourage "tolerance between human beings irrespective of their sexual orientation and identity" and enables children to deal critically with influences from society.
The policy is the statutory guidance for headteachers, governing bodies and local education authorities
The court found the introduction of mandatory RSE had been "the product of a process of careful consideration".
All five claimants have "moral and philosophical objections" to the curriculum and wanted to exercise rights of excusal on behalf of their children to the classes, said Paul Diamond representing them.
"The proposed teaching of RSE in Wales is specifically constructed to be value-laden since much of the teaching, particularly that regarding LGBTQ+, will concern not facts of a scientific nature but highly contentious theories relating to moral and behavioural choices made by individuals," he added.
"Were it to be taught as a stand-alone class and subject to a right of excusal, there would clearly not be any possibility of indoctrination.
"At stake in the present case is the question of whether there is any limit to what can be taught to children in schools or, ultimately, any place including the home and whether the state is to endorse the values of modern, liberal democracy or adopt instead a form of ideological totalitarianism."
However, Jonathan Moffett, representing the Welsh government, rejected the language used by the claimants.
He described "such hyperbolic rhetoric" as "unhelpful", adding the claimants had failed to identify "what allegedly unlawful teaching" the new curriculum would adopt and instead "resort to broad assertions".
"The claimants have not pointed to any passages in the code or the guidance that authorise or positively approve teaching that advocates or promotes any particular identity or sexual lifestyle over another, or that encourage children to self-identify in a particular way," he added.
In the judgement, Mrs Justice Steyn said: "Openness to a plurality of ideas and the ability to engage sensitively, critically and respectfully with such debates, which RSE seeks to encourage and develop, fully accords with the aim of pluralism in a liberal and democratic state."
Welcoming the judgment, education minister Jeremy Miles said he was "appalled by the misinformation that has been purposefully spread by some campaigners".
He added: "Parents can expect schools to engage with them about their plans for teaching RSE and to be able to raise any constructive questions or anxieties they have about those plans.
"We will work closely with schools and communities to ensure that they are heard and they are clear about what their children will and will not be taught."
Kim Isherwood, one of the claimants and spokeswoman for the campaign, said: "We asked the High Court to recognise the overreach of power by the government, we asked the court to help us protect our children from future emotional, physical, and psychological harm.
"The evidence we provided to the court referenced and highlighted concerning levels of betrayal, deceit and false claims made by the government, but it appears as though the judge agrees with them - not only do we parents not have rights, but they were never there to begin with."
He added that the team plans to appeal the ruling to "fight harder to protect our children from a dangerous woke agenda gone off the rails".