Washington-area consumer prices bucked the national trend and rose by 2 1/2 percent during the two-month period ending in July, more than doubling both the comparable national figures and the 1 percent inflation rate for the preceding two-month period, the government said yesterday.

The sharp area increase was based primarily on increases in housing, food and transportation costs, according to statistics prepared by the Department of Labor. The figures, however, do not take into account the seasonal adjustments that are used in determining the national consumer price index.

But the local price increases were also the third highest of those in the 18 large cities measured by government economists. Only the 3.1 percent price increase in the northeast Pennsylvania area around Philadelphia and the 3.0 percent price rise in Miami topped the Washington-area figure.

In nearby Baltimore, consumer prices in June and July rose by only 1.3 percent, even though for the year ended in July 1980, unadjusted prices there rose by 14.2 percent. Inflation in Washington rose by 12.2 percent during the same period.

More than half of the June-July increase here was a result of a rise in the cost of housing, attributable to the two-month combined rise in mortgage interest rates, and in the cost of fuel, particularly the shift to summertime fuel-use rates.

The government's basic local housing index rose by 2.8 percent.The price of basic fuels rose by 10 percent, while the cost of piped gas and electricity rose by 13.6 percent. Food prices made up nearly a quarter of the overall price increase.

In fact, consumer prices in every major category here rose at rates substantially higher than comparable figures for the nation as a whole. Unadjusted consumer prices rose by 1.2 percent across the country, just under half the local rate.

Overall food prices here rose by 3.3 percent for the two months ended with July, compared with a rise of just 1.7 percent for the country. Grocery prices here rose 5.1 percent during the two months, 2 1/2 times the comparable national rate of 2 percent.

Most noticeable in local food price increase was the 13.9 percent jump in the cost of fruits and vegetables at the grocery counter. Nationally, fruit and vegetable prices rose by only 3.0 percent, although government economists point out that the disparity in those figures is in part a reflection of surpluses and cheaper transportation rates in regions close to sources of citrus and other farm products.

But during the same two months in 1979, the cost of fruits and vegetables here rose by only 8.8 percent. For the same two months last year, local prices rose overall by 2 percent. Area prices for beef, pork, eggs and milk also rose during the same period, the government said.

Transportation costs in the Washington area rose by 2.4 percent during June and July, compared to a 0.8 percent jump across the nation. The cost of medical care rose by only 1 percent compared to a national rise of 1.2 percent.