With a massive enough salary, maxing out an HSA as well as a traditional IRA or 401(k) would perhaps be doable year after year. But if you earn more of an average wage, then you may have to set priorities when it comes to funding these tax-advantaged accounts.
You may be inclined to first try to max out a traditional IRA or 401(k) plan before funding an HSA since that money can be used for any purpose in retirement, whereas an HSA is supposed to be earmarked for healthcare expenses. But here's why you may want to do the opposite.
Why your HSA should come first
For the purpose of this discussion, we're going to assume that you're not entitled to any sort of employer 401(k) match to level the playing field. With that in mind, the reason you ought to prioritize an HSA over a traditional IRA or 401(k) is that HSAs offer more tax benefits and more flexibility.
With a traditional IRA or 401(k), you get a tax break on the money you put into your account. You also get to enjoy tax-deferred investment gains.
With an HSA, however, you not only get tax-free contributions, but also, tax-free gains and tax-free withdrawals for money that's used for qualified healthcare expenses. So that's an extra perk right there.
Plus, with a traditional IRA or 401(k), you generally can't touch your money before age 59 1/2 without getting penalized (though there are exceptions). With an HSA, funds are available to you at any time for qualified medical spending. You could take withdrawals in your 20s, 30s, and so forth without having to worry about being penalized for tapping your account early.
Now that said, it is advisable to try to leave your HSA untapped as long as possible, because the more money you have in that account, the more tax-free growth you can enjoy. But you do have the option to take HSA withdrawals for healthcare bills as they arise.
You should also know that once you turn 65, HSA withdrawals taken for non-medical purposes are no longer subject to penalties. What this means is that at age 65, an HSA effectively converts to a traditional IRA or 401(k).
The only difference is that let's say you take a withdraw in retirement from a traditional IRA or 401(k) to cover a medical bill. You'll still pay taxes on that withdrawal. If you tap an HSA in retirement to cover a medical bill, those taxes won't apply.
The best of all worlds
If you're able to max out an HSA on top of a traditional IRA or 401(k), the more power to you. But if you're limited funds-wise, which is the case for many of us, then you may want to first aim to max out your HSA and then focus on your IRA or 401(k).
HSAs really do offer savers the best of all worlds, so it pays to take advantage of one while you can. And remember, HSA eligibility hinges on having a compatible health insurance plan, and having one now does not guarantee that you'll have one in future years. So that's yet another reason to pump as much money as you can into an HSA, even if it means having to contribute less to an IRA or 401(k).