Britain's economy grew by less than expected in July, with the sharp climb in energy tariffs possibly pushing down demand for electricity and a leap in the cost of materials hitting the construction sector.

Gross domestic product expanded by 0.2% from June, official data showed on Monday, weaker than a median forecast of 0.4% and leaving the economy at risk of falling into a recession.

In the three months to July, GDP was flat compared with the previous three-month period.

"Anecdotal evidence suggests that there may be some signs of changes in consumer behaviour and lower demand in response to increased prices," the Office for National Statistics (ONS) said regarding a 3.4% fall in power generation.

Electricity prices leapt by 54% in the 12 months to July, part of the surge in power costs that led to new Prime Minister Liz Truss announcing a cap on domestic energy tariffs last week.

That - and an expected round of tax cuts promised by Truss - has reduced the risk of a severe hit to the economy starting later this year, albeit at a cost of 100 billion pounds ($116 billion) or more to Britain's already stretched public finances.

Last month, the Bank of England forecast that the world's fifth-biggest economy would slip into a recession at the end of 2022 and not come out of it until early 2024, due in large part to the hit to living standards from the energy price surge, caused mostly by the war in Ukraine.

"Our expectation is that the UK economy will contract in Q3 2022, following its -0.1% contraction in Q2 2022," Jake Finney, an economist at PwC, said. "This would mean that the UK enters a technical recession for the first time since lockdown restrictions ended."

Gross domestic production had fallen by 0.6% in June, which included two days of public bank holidays to celebrate the late Queen Elizabeth's 70 years on the British throne.

An ONS spokesperson said the impact of the holidays was not a big factor in July.

Samuel Tombs, at Pantheon Macroeconomics, said a new public holiday scheduled for Sept. 19, the day of the queen's funeral, would reduce economic output by 0.2 percentage points this month, but a recession would probably be narrowly avoided.

Despite the slowing economy, the BoE is expected to raise interest rates again on Sept. 22 as it seeks to combat an inflation rate above 10%.

A heat-wave in July, which brought record-breaking temperatures, might have been another factor behind the fall in power demand although there were signs that it boosted ice cream manufacturers and visits to amusement parks and golf clubs, the ONS said.

Services output grew by a monthly 0.4% in July but industrial production was down 0.3% and construction dropped by 0.8%, reflecting the jump in prices for materials, part of the broader inflation surge, as well as lost working hours because of the extremely hot weather.

Separate trade figures also showed the impact of soaring prices with the value of imports of fuel hitting an all-time high of 11 billion pounds in July and representing a record 21% of all goods imports.

($1 = 0.8609 pounds) (Reporting by William Schomberg and Andy Bruce; editing by Philippa Fletcher and Toby Chopra)