By Rodrigo Campos

(Reuters) - U.S. stocks rose on Tuesday, led by gains in technology shares as Federal Reserve Chair Janet Yellen was optimistic about the economy and played down the risk of a recession, while concern over the upcoming British referendum remained subdued.

Yellen, however, warned that the British vote on Thursday on whether to stay in the European Union, alongside a U.S. hiring slowdown, posed risks to the economic outlook.

The British pound earlier brushed $1.48 to hit its highest level in nearly six months versus the U.S. dollar <GBP=>, as markets continued to price in the momentum toward a vote to remain in the EU.

"The biggest issue in the market is clearly the upcoming vote in the UK. The sentiment swings back and forth and right now it is swinging toward 'remain' and that is giving support," said Rick Meckler, president of LibertyView Capital Management in Jersey City, New Jersey.

The Dow Jones industrial average <.DJI> rose 24.86 points, or 0.14 percent, to 17,829.73, the S&P 500 <.SPX> gained 5.65 points, or 0.27 percent, to 2,088.9 and the Nasdaq Composite <.IXIC> added 6.55 points, or 0.14 percent, to 4,843.76.

Microsoft <MSFT.O> led the S&P advance with a 2.2 percent gain followed by Apple's <AAPL.O> 0.8 percent rise.

As part of its biannual monetary policy report, the Fed warned U.S. stock market valuations are "well above" their median over the past 30 years, the strongest such assessment in years.

"The model they use may be useful in long periods of time, but hasn't proved to be useful in the short run," Meckler said, as he pointed to the low returns investors get from Treasury yields and a near-zero return on cash that is partly due to Fed policies.

"They inflated the asset class (stocks) and then they say, ‘Gee, it’s inflated’."

The S&P 500 is trading at about 16.5 times expected earnings, above the 30-year median of 14.6 times, according to Thomson Reuters Datastream.

The energy sector <.SPNY> led gains on the S&P 500 with an advance of 1.1 percent despite declines in crude oil futures.

Drugmaker Celgene <CELG.O> was the biggest weight on the S&P with a 2.4 percent decline to $96.86. Traders said they were fielding questions on Tuesday about the Independent Payment Advisory Board, which is intended to control costs under the Medicare government health program; analysts say creation of the IPAB board could be triggered as soon as this week.

United Continental <UAL.N> rose 3.4 percent to $44.86 after the airline operator laid out plans to generate an extra $3.1 billion in operating income per year by 2018.

Advancing issues outnumbered declining ones on the NYSE by a ratio of 1.30-to-1 while on the Nasdaq a 1.35-to-1 ratio favored decliners.

The S&P 500 posted 28 new 52-week highs and 3 new lows; the Nasdaq recorded 47 new highs and 57 new lows.

About 6.2 billion shares changed hands in U.S. exchanges, compared with the 6.83 billion daily average over the past 20 sessions.

(Reporting by Rodrigo Campos; Editing by Nick Zieminski and Meredith Mazzilli)