The US Supreme Court has ruled that federal protections against workplace discrimination apply equally to sexual orientation, contrary to the position taken by the administration of President Donald Trump.

The landmark decision said Title VII of the Civil Rights Act of 1964, which outlaws discrimination against employees because of a person's sex, also covers sexual orientation and transgender status.

"Today we must decide whether someone can be fired simply for being homosexual or transgender," the court said. "The answer is clear."

Gay, lesbian, bisexual and transgender rights (LGBT) activists, as well as Democratic politicians and several major businesses had been demanding that the court spell out that the community was protected by the law.

Andrew Cuomo, the Democratic governor of New York state, said on Twitter, "This #SCOTUS decision is a major victory for #LGBTQ rights.

"No one should be discriminated against based on their sexual orientation or gender identity," he added.

In 2015, the Supreme Court ruled  same-sex marriage to be legal, a landmark victory for the LGBTQ community.

But rights activists feared that the appointment by President Trump of two new conservative judges to the top court could hinder further wins for their case.

Yet it was one of them, Neil Gorsuch, who wrote the majority decision, joining with the court's four progressive judges and Chief Justice John Roberts.

Conservative judge Neil Gorsuch (L) wrote the majority decision

"An employer who fires an individual for being homosexual or transgender fires that person for traits or actions it would not have questioned in members of a different sex. Sex plays a necessary and undisguisable role in the decision, exactly what Title VII forbids," Mr Gorsuch wrote.