Last year's stock market sell-off highlighted the importance of investing in solid growth stocks over the long term. Doing so can safeguard your investment from temporary headwinds like the economic declines that burdened many companies in 2022. Meanwhile, choosing to invest in businesses with a history of consistent financial growth and significant market share in their respective industries can further boost the potential for reliable gains.

Apple (AAPL 2.20%) and Costco (COST 1.42%) are two attractive options, with one leading the consumer tech market and the other making promising inroads in other aspects of retail worldwide. These companies' stocks have risen over 150% in the last five years, with annual revenue increasing by over 48% in the same period. Furthermore, Apple and Costco are home to potent brands that have amassed immense brand loyalty from consumers, strengthening the arguments in support of their stocks.

Here are two roaring stocks to hold for the next 20 years.

1. Apple 

As the most valuable company in the world with a market cap of $3 trillion, it's no surprise Apple is a favorite on Wall Street. In fact, investment mogul Warren Buffett's holding company Berkshire Hathaway has entrusted the iPhone company with 47% of its portfolio. For reference, its second-biggest holding is Bank of America, with 8%. 

AAPL Chart

Data by YCharts.

Apple is renowned for its stock's stability and reliable growth, even in economically challenging conditions. As the chart above shows, Apple experienced the smallest stock decline last year out of what's considered the "Big Five" of tech. Despite the entire industry suffering pullback from consumer spending, the company reported an 8% year-over-year rise in revenue. Meanwhile, its highest earnings segment, the iPhone, enjoyed a 14% increase in revenue as demand remained high for its smartphones.

Apple's stock makes a particularly attractive long-term investment thanks to its nearly unrivaled brand loyalty. This allegiance from consumers allowed the company to overtake Alphabet's Android for a majority market share in U.S. smartphones last year and similarly achieve leading market shares in many of its other product categories. The connectivity between all of the tech company's products has become a winning strategy that makes consumers less likely to use competing devices if Apple is an option.

Moreover, the MacBook manufacturer's dominance in consumer tech strengthens the potential of its recently revealed virtual/augmented reality (VR/AR) headset, the Vision Pro. According to Fortune Business Insights, the VR market is projected to expand at a compound annual growth rate of 45% through 2029 and hit $227 billion. The first Vision Pro will likely be held back by its price tag of $3,499. However, future generations of the device could see the price come down and allow Apple to dominate the high-growth sector.

As a stock that has risen 305% in the last five years and over 1,100% in the last decade, Apple is an excellent stock to hold for 20 years and beyond.

2. Costco

Similar to Apple, Costco has managed to attract loyal customers worldwide. The company's wholesale setting and annual subscription fee have allowed it to offer shoppers competitive pricing, making it one of the best retail stocks available. The chart below shows that Costco shares have enjoyed significantly more growth since 2018 than retail competitors such as Amazon, Walmart, and Target

COST Chart

Data by YCharts.

Meanwhile, the company's earnings have continued on a promising trajectory, with annual revenue up 60% in the last five years and operating income up 74%.

Additionally, despite Costco's founding nearly four decades ago, the company is nowhere near hitting its ceiling. The retail giant boasts 855 locations in 14 countries and has massive growth potential. Costco has four or fewer locations in six of those countries, suggesting plenty of expansion opportunities within those regions and beyond.

For instance, the company opened its first store in France in 2017, with the location becoming a massive hit with locals. Costco has since opened a second location and plans to have 15 stores in the country by 2025.

Costco's stock is slightly expensive according to its price-to-earnings ratio of 40. However, its consistent stock growth and swiftly rising earnings make it an attractive option to buy now and hold indefinitely.