House Democrats approved legislation on Thursday to repeal part of the 2017 Republican tax law — but the effort may show just how difficult it will be to undo President Trump’s landmark legislation.

Democrats only narrowly approved the bill, which would restore a tax break that had been sharply restricted by the 2017 Republican tax law. The bill, which passed 218-206, would allow Americans to offset more state and local payments from their income taxes.

The bill is expected to amount to little more than a messaging exercise, however. Senate Republicans have signaled they won’t bring it to a vote, and the White House has also expressed opposition.

The 2017 tax law has continued to vex Democrats, who have said it primarily helps wealthy Americans and corporations. But analysts and tax experts say the bill House Democrats advanced on Thursday would primarily benefit affluent Americans. That’s because it would repeal a cap on state and local tax (SALT) deductions, a change that would benefit people with large tax bills.

Republicans exploited this dynamic on Thursday, submitting an amendment to redirect the benefits of eliminating the cap for those earning more than $100 million. Rep. Tom Rice (R-S.C.) said the $7 billion in savings from that move should go toward doubling a deduction for teachers and firefighters on supplies. That measure was overwhelmingly accepted by Democrats and incorporated into the legislation, despite opposition from liberal lawmakers in the Congressional Progressive Caucus.

Supporters of the bill say it is designed to address the effect on households in states such as Massachusetts, New Jersey, New York and California, where people could pay tens of thousands of dollars in state and local taxes. The 2017 tax law capped the amount of these taxes that households could deduct at $10,000.

Democrats say they are offsetting the revenue that would be lost by repealing the SALT cap by restoring the top tax rate paid by the highest earners — from 37 percent to 39.6 percent. The House bill also only temporarily repeals the tax cap, and it would go back into effect after several years.

Their vote to repeal a large tax provision that would affect the affluent comes during a push by many of the party’s leading presidential candidates to dramatically raise taxes on wealthy Americans to fund an array of new government programs. This tension underscores the challenge of paying for liberals’ ambitious spending goals, tax experts said.

Liberal tax experts cited data from the Tax Policy Center, a nonpartisan think tank, indicating that about 99 percent of taxpayers earning less than $100,000 would see no benefit from the repeal of the cap.

By 2021, about half of the benefit of repealing SALT would go to those who earn more than $1 million, according to the Joint Committee on Taxation, a nonpartisan congressional body. Almost no benefits would go to those earning less than $100,000, the analysis found.

Only 16 Democrats voted against the legislation, including liberal Reps. Alexandria Ocasio-Cortez (N.Y.), Mark Pocan (Wis.) and Lloyd Doggett (Tex.).

“This mostly benefits rich people,” Steve Wamhoff, a tax analyst at the Institute on Taxation and Economic Policy (ITEP), a left-leaning think tank, said of repealing the SALT cap.

“There’s a disconnect here: Many Democrats understand we have to raise more money to make the tax code more progressive,” Wamhoff said. “But this proposal, taken on its own, does not do that. It’s a big problem.”

The GOP tax law limited the state and local tax payments that Americans could deduct from their taxable income. Under the previous tax code, taxpayers could face some limits on their deductions, but they were able to deduct much more than they can now.

The change disproportionately affected states run by Democrats, where residents — because of higher state taxes and high land values that push up property taxes — tend to pay more to their local and state governments.

Republicans included the cap in their tax law to offset the enormous cost of their $1.5 trillion tax cut, which made a number of changes but primarily cut the tax rate paid by corporations from 35 percent to 21 percent. Democratic lawmakers have said the SALT cap deprives high-tax communities of crucial funding, while also affecting middle-income people in high-cost areas who are still suffering from the change.

Rep. Thomas Suozzi (D-N.Y.), who sits on the House Ways and Means Committee, has helped lead the Democratic charge to repeal the cap.

Rep. Peter T. King (R-N.Y.) said in a floor speech on Thursday that the SALT cap not only hits rich people, but also affects police officers, firefighters and construction workers, noting that blue-collar workers in the New York City area can earn salaries that would make them appear affluent elsewhere in the country.

The bill also enjoyed the support of liberal makers in the Congressional Progressive Caucus, such as Rep. Katie Porter (D-Calif.), who spoke in support of the package.

“The elimination of the deduction compounds the already high cost of living on Long Island and is driving people from their homes to places where the cost of living is lower. As a result, communities are losing tax revenue which should be going to critical municipal services,” Suozzi said in a statement this summer.

Rep. Kevin Brady (R-Tex.), a member of the House Ways and Means Committee, said the Democrats’ plans would give basketball star LeBron James a tax break of more than $2 million, while offering nothing for low-wage workers at the Staples Center, home of the Los Angeles Lakers.

“With this bill, you’ve officially claimed the mantle, ‘The party of the rich,’ ” Brady said.

Several liberal economists and think tanks have also argued that repealing the cap would primarily benefit the wealthy and should not be a Democratic priority, even as the Democratic-controlled House has ignored those warnings. Some have also dismissed the claim that the SALT cap is driving people out of high-tax areas.

Restoring the top income-tax bracket to 39 percent would raise substantial sums, but it is doubtful doing so would permanently offset the cost of repealing the cap. ITEP estimates that even when combined with restoring the top tax rate to 39.6 percent, repeal of the cap on SALT deductions would cost about $80 billion a year.