Want to beat the market, but aren't sure which stocks to invest in? One strategy to consider is investing in exchange-traded funds (ETFs). On one hand, they offer diversification that can reduce some of the risk that comes with picking individual stocks. And at the same time, they offer opportunities to focus on industries that have generally outperformed the markets -- industries, for example, like healthcare.

The iShares U.S. Healthcare ETF (IYH 0.46%) and the iShares U.S. Healthcare Providers ETF (IHF -0.29%) have beaten the S&P 500 over the past decade, and both could be great options for long-term investors to buy now.

1. iShares U.S. Healthcare ETF

If you want broad exposure to the healthcare industry, then the iShares U.S. Healthcare ETF can give you just that. It focuses on domestic healthcare stocks, with the largest fraction of the fund made up of pharmaceutical stocks. Those account for 30% of the ETF's weight. Companies involved with healthcare equipment are the next largest segment at 19%, followed by biotech stocks at just under 18%.

The fund's top three holdings are UnitedHealth Group, Johnson & Johnson, and Eli Lilly -- three stalwarts in the healthcare industry. Other big names in the fund include AbbVie and Pfizer. As you'll notice, with this ETF, investors are getting the best of the best in healthcare stocks to own. And with an expense ratio of 0.39%, the fund's fees won't eat up a big chunk of your earnings.

The ETF also pays a dividend that yields a little over 1%. And when combined with that dividend, its returns over the past 10 years total 252% -- higher than the S&P 500's total returns of 226%. A $10,000 investment in the ETF made a decade ago would be worth around $35,000 (before fees) today versus less than $33,000 if you invested in a fund mirroring the S&P 500.

2. iShares U.S. Healthcare Providers ETF

For investors looking for a more specialized fund that focuses on health insurance, diagnostics, and specialized treatments, the iShares U.S. Healthcare Providers ETF could be a good option to consider. Its portfolio has 69 holdings, in contrast to the U.S. Healthcare ETF, which has 113.

Managed healthcare companies account for 43% of its weight, followed by healthcare services at 39%, and healthcare facilities at 14%. UnitedHealth Group is one of this ETF's top holdings too, but CVS Health and Elevance Health round out its top three.

The benefit of a more narrowly focused ETF is that it can sometimes deliver better returns. Too much diversification can chip away at your overall returns since in a portfolio with more holdings, the top-performing stocks often account for smaller slices of the total fund.

For example, while UnitedHealth Group is the top holding in both ETFs, in the Healthcare Providers fund, it makes up 21% of the ETF's total weight versus just 9% in the broader U.S. Healthcare ETF. Since UnitedHealth Group has performed well over the past 10 years (its total returns are a whopping 910%), the U.S. Healthcare Providers ETF has benefited more from that, and delivered a higher total return of 286%.

It's hard to go wrong with either fund

While both funds have generated excellent returns over the past decade and are full of solid healthcare stocks, investors should weigh the diversification issue carefully when deciding which is the better option for their preferred level of risk and desired exposure. 

Overall, investing in healthcare ETFs can be a solid way to earn a good return, as healthcare spending is likely to keep rising as the share of the U.S. population who are of retirement age climbs. According to data from the Centers for Medicare & Medicaid Services, national health spending is expected to increase by 5.5% per year until 2027 -- significantly faster than expected gross domestic product growth. 

For long-term investors, buying shares of either of these ETFs could set you up for some great gains in the future.