The UK Supreme Court has ruled that the Scottish Government's hotly-debated Named Person scheme, in its current form, is "incompatible" with children's human rights.

The Scottish Government has welcomed the judgment, which calls for the legislation to be altered rather than scrapped entirely.

The Supreme Court, Scottish ministers say, accepted that the policy's aims were "benign".

So what is the Named Person scheme and why has it proved so controversial?

It is a scheme that would assign every single child in Scotland under the age of 18 a state-appointed "named person", with the aim of creating a single point of contact for parents or children who need advice, information or support relating to the welfare of children and young people.

Passed by the Scottish Parliament in 2014 under the Children and Young People Act as part of the government's Getting it Right for Every Child strategy (Girfec), it was due to come into force on August 31.

In most cases, the named person would be a teacher, a midwife, or a health visitor, depending on the child's age, although organisations like the Scottish Prison Service would also have been obligated to provide a named person for young people in their care.

The Scottish Government says the scheme should act as a safety net only for families or children who request support, although have also said a named person could also intervene "when wellbeing needs are identified".

These needs could be flagged up to other professionals, such as doctors.

The SNP government is joined in support of the scheme by the Scottish Greens and the Scottish Lib Dems, and although Scottish Labour called for a "pause" during the Holyrood election campaign, they joined the other three parties in voting in favour of the policy in June.

They in turn are joined by leading children's charities, including Barnardo's Scotland, Children 1st, Aberlour and the NSPCC.

In the Scottish Parliament, opposition to the legislation has been led by the Scottish Conservative Party.

They are joined by an alliance of civil liberties groups, Christian and family organisations and the Young ME Sufferers Trust, who have campaigned under the banner NO2NP.

A Survation poll in June also found the majority of the Scottish public oppose the scheme, with 64% calling it an "unacceptable intrusion" into family life.

Ministers say the purpose of the legislation is to ensure that cases of child abuse and neglect as well as examples of struggling parents and families do not slip through the cracks, by providing extra support where appropriate.

Supporters say a pilot scheme in the Highlands has been successful, while charities point to benefits such as a reduction in "excessive red tape or delay" in helping families access services they need.

Opponents of the legislation claim it marks an unprecedented and illiberal intrusion by the state into family life, and that it sanctions government "snooping".

Critics also say that the universalism of the scheme will stretch resources for families and children who truly need support.

Family groups also say that the scheme could undermine parents and the institution of family more generally.

The court ruled that provisions in the legislation around the sharing of information were "incompatible" with the rights of children and young people under Article 8 of the European Convention on Human Rights (ECHR), which enshrines the right to privacy.

It added that these provisions could cause named persons to disproportionately interfere with these rights due to "limited safeguards".

The Scottish Government insists that the legislation will be "implemented nationally at the earliest possible date" once the provisions singled out by the Supreme Court have been satisfactorily changed.

Deputy first minister John Swinney added that the purpose of the appeal against the legislation was to force it to be scrapped entirely and that it had "failed".