ONS said that rising motor fuel prices fuelled inflation as petrol prices rose strongly during the period.
The figures suggest that the recent falls in inflation have ended, at least temporarily and inflation is proving stubborn to reduce.
There were large upward forces from air and sea fares, which rose between April and May this year but fell between the same two months a year ago, influenced by the timing of Easter.
There were downward forces from price changes for games, domestic electricity, food and non-alcoholic beverages, and furniture and furnishings.
Kevin Doran, chief investment officer at AJ Bell, said: “The Bank of England will be disappointed to see inflation holding firm at 2.4%, some way above its 2% target.
“The Monetary Policy Committee unanimously decided against an interest rate rise in May and will now be watching inflation very closely to see if this is a temporary blip in the downward trend or if it starts going up again. The rising oil price and recent weakness in the pound are unlikely to help here.
“If inflation continues to hold firm or even increases, UK consumers will once again start to feel the pinch. Wage growth, including bonuses, is currently only marginally ahead of inflation at 2.5% and interest rates on cash savings remain rock bottom so rising prices will weaken the spending power of both earnings and savings.”
Ben Brettell, senior economist, Hargreaves Lansdown, said: “Following yesterday’s weak wage growth numbers, today’s news that inflation held steady at 2.4% in May provides further food for thought for the MPC, as they consider an August rate rise.
Market reaction to the data was muted, with sterling losing marginally and the FTSE slightly higher, he added.
Inflation had been expected to tick up to 2.5%, but the unchanged headline number masks a few details which could show inflationary pressure is beginning to build, says HL. Output price inflation rose for the first time in six months, with prices rising 2.9% in the year to May compared with 2.5% in April. Companies' raw material costs jumped 9.2% on the year.
Yesterday’s wage growth numbers were lower than expected and data released on Monday showed manufacturing output dropped in April.
• Editor's Note: The chart shows CPI and CPIH inflation over the past 10 years along with OOH (Owner Occupier Housing costs)