The Nasdaq composite posted a record close on Monday, led by shares of Apple and Amazon.
The tech-heavy index rose 0.7 percent to 7,606.46 as Apple and Amazon gained 0.8 percent and 1.5 percent, respectively. Apple and Amazon also posted record closing highs. The Nasdaq also closed less than half a percent away from an intraday record.
"If you look at the month of May, Apple — all by itself — contributed 23 percent of the S&P 500's gains," said Jeff Kilburg, CEO of KKM Financial on CNBC's "Worldwide Exchange." "When you see Apple at all-time highs, that is the sentiment, that is the true revelation that we are OK in the U.S. economy."
Microsoft also helped lift the Nasdaq, rising 0.9 percent to a record after announcing it was acquiring GitHub, a software developer platform, for $7.5 billion. Other tech names hitting all-time highs on Monday included Adobe, Electronic Arts and Netflix.
Monday marked the first record closing high for the Nasdaq dating back to March 12, when it closed at 7,588.32. The index fell more than 10 percent after hitting that level before bouncing back.
The Dow Jones industrial average closed 178.48 points higher at 24,813.69, while the climbed 0.5 percent to 2,746.87 as tech closed at a record high.
A rise in retail stocks also boosted the major indexes. Walmart and Target rose 2.9 percent and 4.9 percent, respectively. The SPDR S&P Retail exchange-traded fund (XRT) also gained 2.2 percent, its biggest one-day gain since April 4.
Monday's gains come after the major indexes rallied on Friday on better-than-expected economic news. The Dow gained 219 points after the Labor Department said Friday that the U.S. economy added 223,000 jobs last month, a figure that topped expectations.
"The market seems to be focused on the economy and not so much on the potential consequences from trade tensions," said Peter Cardillo, chief market economist at Spartan Capital Securities. "Tensions are high. The question is whether Trump will smooth things out or make them worse [at the G7 summit]. We'll have to wait and see."
Leaders from seven of the largest economies in the world are set to meet in Canada this week at a time when trade tensions between the U.S. and key trade partners have increased.
Last week, the Trump administration slapped tariffs on steel and aluminum imports from the European Union and Canada. The EU threatened the same, saying it would impose countermeasures of its own, while Canada Foreign Minister Chrystia Freeland said the country plans to slap dollar-for-dollar tariffs on the U.S.
"Multilateral tariffs are certainly a warning sign that this is no longer merely a case of US protectionism and that the world is edging towards a trade war," said Oliver Brennan, senior macro strategist at TS Lombard, in a note. "In such a circumstance, global trade growth could fall by 10pp and global GDP by over 1.5pp (according to IMF estimates, after five years).
"The impact of tariffs has been mostly restricted to those sectors that are directly affected. Retaliation is likely to widen the impact and increase political risk, but for now the US economy continues to motor on," Brennan said.
— CNBC's Cheang Ming contributed to this article.