High gasoline prices are prodding more people to consider an electric vehicle. But car shoppers are likely to face sticker shock at the dealership, too.

Auto makers have been raising prices on electric cars, partly to offset the soaring cost of materials used in their large batteries. Car executives also are capitalizing on strong consumer interest in EVs, as a new wave of plug-in vehicles hits the market.

In the past few months, Tesla Inc., TSLA 4.52% Ford 3.89% Motor Co., General Motors Co., GM 5.55% Rivian Automotive Inc. and Lucid Group Inc. have increased prices on certain electric models.

Last week, GM tacked on $6,250 to the price of GMC Hummer electric pickup-truck models, which now range from around $85,000 to $105,000, citing an increase in commodity and logistics costs. The waiting list for the recently released truck is about two years, a GM spokesman said.

Tesla this year has increased prices three times for a performance version of its top-selling Model Y SUV, adding a total of about 9% to the sticker price, which is now $69,900, according to Bernstein Research.

Overall, the average price paid for an electric vehicle in the U.S. in May was up 22% from a year earlier, at about $54,000, according to J.D. Power. By comparison, the average paid for an internal-combustion vehicle increased 14% in that period, to about $44,400.

The companies say they are trying to offset a recent price rise in raw materials that go into the batteries to power electric cars, by far the most expensive component of an EV. Prices for lithium, nickel and cobalt have roughly doubled since before the Covid-19 pandemic began, according to consulting firm AlixPartners LLP.

Ford finance chief John Lawler said last week that rising EV commodity expenses have wiped out the profit margin on Ford’s Mach-E SUV. Ford has raised prices in an effort to offset the cost inflation, he said.

With gas prices on a wild ride, many consumers are exploring whether buying an electric vehicle could save them money in the long run. WSJ’s George Downs breaks down four factors to consider when buying a new car. Photo composite: George Downs

Major auto makers are rushing to roll out a range of electric vehicles, motivated by tightening air-pollution regulations, shareholder concerns about climate change and Wall Street’s enthusiasm for the growth potential of EVs.

The amount of money the auto industry has earmarked toward EV development has doubled over the past two years, AlixPartners estimates. Companies are expected to spend $526 billion combined on the transition to EVs over the five-year period ending in 2026, the firm said.

Elevated raw-material prices could complicate that effort, analysts say. Profit margins on EVs are small relative to gas-powered cars because the cost of the large battery pack to power such vehicles was high before recent inflation, as much as one-third the total vehicle cost.

To protect their bottom lines, car companies need to work closely with materials producers—even directly with the companies mining lithium and cobalt, for example—to ensure supplies and control costs, Credit Suisse analyst Dan Levy wrote in an investor note this month. Tesla, GM and other car makers have signed such direct-supply deals.

If raw-material costs eventually ease, car companies may need to reduce prices to sustain demand beyond early adopters, Mr. Levy said.

For now, auto executives say they generally aren’t worried about price increases hurting consumers’ appetite for EVs.

Demand for models now hitting the market has been stronger than many of the companies expected when they set their pricing plans a few years ago, executives have said. Some new EVs have racked up tens of thousands of reservations and yearslong waiting lists.

“The demand for EVs right now is extremely robust at Ford. So we have the opportunity, we believe, for pricing,” Ford Chief Executive Jim Farley told analysts in April.

“We’re in a world where it almost seems like [limitless] in terms of willingness to pay,” Rivian RIVN 0.10% Chief Executive RJ Scaringe said at an investor conference this month. Rivian in March raised prices by around 20% on some models. However, he said: “We don’t believe this will forever be the case.”

GM departed from the trend this month by cutting the Chevrolet Bolt’s price in the U.S. by about $6,000, to about $27,000, among the least expensive EVs on the market. The company said it wants to position the car, which was subject to a large safety recall last year to fix faulty battery cells, as an affordable option.

Higher gas prices are stoking interest in EVs, according to a survey this spring from car-shopping site TrueCar. More than half of respondents said they were more likely to consider an EV because of rising prices at the pump.

Some EV buyers qualify for a $7,500 federal tax credit. GM and Tesla electric vehicles no longer qualify because those companies reached a manufacturer sales cap of 200,000 vehicles.

Still, electric-vehicle sales in recent months accounted for only about 5% of overall U.S. sales. Car companies eventually will need to make EVs accessible to more than the affluent, said Tyson Jominy, vice president of data and analytics at JD Power.

“For mass consumer adoption, the industry still has to find a way to get cheaper EVs to market,” he said.

It is unclear whether car makers will reduce prices on their existing electric models if commodity prices eventually decline. Tesla Chief Executive Elon Musk said this spring that cutting prices in the future is a possibility.

Mr. Musk told analysts during Tesla’s quarterly conference call that Tesla is trying to anticipate its own cost increases, and stay ahead of them. He said some suppliers were asking for increases of as much as 30%.

“The current prices are for a vehicle delivered in the future, like six to 12 months from now,” Mr. Musk said. “So this is our best guess.”