The increase matches what analysts had expected and pushes the measure to its highest since early 1982, according to ONS estimates.
“Though still at historically high levels, the annual inflation rate was little changed in May,” said ONS chief economist Grant Fitzner.
“Continued steep food price rises and record high petrol prices were offset by clothing costs rising by less than this time last year, and a drop in often fluctuating computer games prices.
“The price of goods leaving factories rose at their fastest rate in 45 years, driven by widespread food price rises, while the cost of raw materials leapt at their fastest rate on record.”
The change was in large part driven by the increase in food prices, which added more than 0.2 percentage points to the inflation number, the ONS said.
Clothing and footwear prices helped keep a lid on inflation, while recreation and culture prices also pulled it downwards.
The news will add to the difficulties faced by many people across the UK. Energy bills rose by 54% for the average household at the beginning of April and will remain at this level until October.
But forecasts released this week predict that the Government cap on energy bills could rise again from an already record high £1,971 to £2,980 in the autumn.
The Bank of England has predicted that inflation will spike at more than 11% in October after the price cap is changed again.
Deputy Prime Minister Dominic Raab said the rising inflation figures showed the need for pay restraint in the public sector and on the railways.
He told Sky News there was a risk of a “vicious cycle” of rising wages pushing inflation even higher if union demands were met, saying the Government was taking a “firm line”.
“We are facing a global struggle against inflation, if you look at the UK figures they are broadly comparable to the US or, in Europe, the Dutch and the Belgians, and it’s going to be difficult.
“We really do understand the pressure that those on low incomes are facing at the moment, they are struggling to make ends meet.”
Shadow chancellor Rachel Reeves said: “Today’s rising inflation is another milestone for people watching wages, growth and living standards continue to plummet.
“Though rapid inflation is pushing family finances to the brink, the low wage spiral faced by many in Britain isn’t new.
“Over the last decade, Tory mismanagement of our economy has meant living standards and real wages have failed to grow.”
Chancellor Rishi Sunak said: “I know that people are worried about the rising cost of living, which is why we have taken targeted action to help families, getting £1,200 to the eight million most vulnerable households.
“We are using all the tools at our disposal to bring inflation down and combat rising prices – we can build a stronger economy through independent monetary policy, responsible fiscal policy which doesn’t add to inflationary pressures, and by boosting our long-term productivity and growth.”