Image copyright AP Image caption Gavin Grimm, 16, identifies as male

A US appeals court has ruled that a Virginia school policy that barred a transgender student from using the boys' toilet is discriminatory.

Gavin Grimm filed the lawsuit after the school board adopted a policy that required students to use a private toilet or one that corresponds to the sex listed on their birth certificate.

Grimm, who identifies as male, said the policy was stigmatizing.

How transgender people use public toilets is a divisive issue in the US.

A number of places in the US - most recently North Carolina - have passed laws requiring transgender people to use a public toilet that corresponds to the sex listed on their birth certificate.

The North Carolina law in particular has been sharply criticised as discriminatory and several companies have stopped doing business in the state as a result.

In the Grimm case, the three-judge panel found the Gloucester County District policy violated Title IX, a federal law which prohibits gender discrimination at schools that receive federal funding.

The Gloucester County District said the policy was meant to respect the privacy of all students.

Image copyright Reuters Image caption Gender-neutral toilets are becoming more common in some parts of the US

A federal judge had earlier rejected Grimm's sex discrimination claim, saying Title IX only protects students from discrimination based on biological sex, not gender identity.

Other federal rulings in similar cases have also ruled that Title IX does not apply to transgender students.

This federal ruling could have wider implications because it creates a legal precedent in five states including North Carolina. The America Civil Liberties Union (ACLU) and others have already filed a challenge to North Carolina's transgender law.

Some supporters of these policies said allowing transgender people to choose their restroom could lead to women and children being attacked.

They said they feared that predatory men could pose as transgender people and use legal protections as a cover.