WASHINGTON — Major internet companies were put on defense on Capitol Hill on Tuesday for their opposition to a piece of legislation designed to root out online sex trafficking.

The bill, sponsored by Sen. Rob Portman (R-Ohio) and more than two dozen others, would amend a section of the Communications Decency Act that has shielded internet companies from liability for user-generated content posted on their sites. The legislation would create new liability for internet firms that “knowingly facilitate sex trafficking” via the content they host on their platforms.

“Silicon Valley holds itself out as being more than just another industry, but rather a movement to make a world a better place,” Portman told the committee. “… But the selling of human beings online is the dark side of the internet. It can’t be the cost of doing business.”

But major internet providers, while acknowledging the urgency of addressing the growth of online sex trafficking, say that the legislation is too broadly written.

Abigail Slater, the general counsel of the Internet Association, which includes Google and Facebook among its members, told the committee that they seek “targeted legislative changes” but they are concerned that the current bill will open up legitimate sites to frivolous lawsuits. She said that language in the bill created a “vague knowledge standard” that could expose companies to such litigation.

She said that the association favors an amendment to the legislation that would allow for civil suits against internet sites that have knowledge and intent to serve as facilitators of online sex trafficking.

Sen. Ron Wyden (D-Oregon) said that the legislation “being considered today the wrong answer to a series of important questions.” He noted that he was a co-author of the Communications Decency Act section that shields internet firms from liability, and at the time they intended for it to make sure that “bad actors would still be subject to federal law.”

The bill has created a dicey situation for the internet lobby, which is unhappy with the language of the legislation but may not be able to stop a bill that has drawn bipartisan support. After years in which their influence has been on the upswing on Capitol Hill, major internet companies are now feeling some heat from lawmakers, not just on the sex-trafficking legislation but in other areas. Sen. Mark Warner (D-Va.) has said that he would like Facebook and Twitter representatives to testify on the use of their platforms by Russian-connected interests during the 2016 presidential campaign.

Last week, 21st Century Fox, which has found itself at odds with Google on issues like piracy, announced its support for the legislation.

At the Tuesday hearing, though, a lot of focus was placed on Backpage.com, which shut down its adult classifieds section earlier this year amid charges that its advertisements included those for childhood prostitution.

At the hearing, California Attorney General Xavier Becerra said that “we are fighting with two hands behind our backs” when it comes to prosecution of online sex trafficking.

Among those who also testified was Yvonne Ambrose, whose 16-year-old daughter was murdered last year. She said that her daughter was a victim of sex trafficking, and sued Backpage.com earlier this year for hosting the advertisements that promoted prostitution.