U.S. President Barack Obama on Wednesday signed and celebrated hate crime legislation that extends protection to people based on sexual orientation.

The new law expands federal hate crimes to include those committed against people because of gender, sexual orientation, gender identity or disability.

It also loosens limits on when federal law enforcement can intervene and prosecute crimes, amounting to the biggest expansion of the civil rights era law in decades.

"No one in America should ever be afraid to walk down the street holding the hands of the person they love," Obama said in an East Room reception, surrounded by joyous supporters.

"No one in America should be forced to look over their shoulder because of who they are, or because they live with a disability."

Civil rights groups and their Democratic backers on Capitol Hill have tried for a decade to expand the hate crimes law, but fell short because of a lack of co-ordination between the House and Senate, or opposition from former president George W. Bush.

Attached to defence funding

This time, the bill got through when Democrats attached it to a must-pass $680-billion-US defence measure. Obama signed the combined bill in a separate ceremony earlier Wednesday.

Conservatives have opposed the legislation, arguing it creates a special class of victims and could serve to silence clergymen or others opposed to homosexuality on religious or philosophical grounds.

The bill was named for Matthew Shepard and James Byrd, whose family members stood with Obama.

Shepard, a gay college student, was murdered and found tied to a fence in Wyoming in 1998. The same year, Byrd, a black man, was chained to a pickup by three white men and dragged to his death in Texas.

"We must stand against crimes that are meant not only to break bones, but to break spirits; not only to inflict harm, but to instill fear," Obama said.

Groups pushing for the expanded civil rights protections rejoiced.

"This is a landmark step in eliminating the kind of hate-motivated violence that has taken the lives of so many in our community," said Jarrett Barrios, president of the Gay & Lesbian Alliance Against Defamation.

Hate crimes law enacted after the assassination of Martin Luther King Jr. in 1968 centred on crimes based on race, colour, religion or national origin.

Some 45 states have hate crime statutes, and the bill would not change current practices where hate crimes are generally investigated and prosecuted by state and local officials.

But it does broaden the narrow range of actions — such as attending school or voting — that can trigger federal involvement and allows the federal government to step in if the Justice Department certifies that a state is unwilling or unable to follow through against an alleged hate crime.

At the urging of Republicans, the bill was changed before it was passed in Congress to strengthen free speech protections to assure that a religious leader or any other person cannot be prosecuted on the basis of his or her speech, beliefs or association.