Introduction to HSAs: https://www.investopedia.com/terms/h/hsa.asp
I transitioned to an HSA-style health plan last year, and I'm loving it. The plan is a higher-deductible than a traditional health insurance plan, but fortunately, I'm not incurring many medical expenses now. I don't anticipate I'll meet my deductible in any event. So rather than wasting a bunch of money on health premiums each month, I get to sock that money away for later.
For many HSA plans, once you reach a certain amount of money in the account (my threshold is $1,000), then the plan allows you to invest your money like a 401(k) or other retirement account.
And if you are so lucky enough that you never have to use your HSA money for any health expenses by the time you turn 65, then you can actually get your money back:
--"Once you turn 65 years of age, your Health Savings Account is liberated substantially. You are free to spend your HSA funds on whatever you want, not just qualified medical expenses. Note that any distribution for non qualified medical expenses will be taxed (just like ordinary income), but at least you are getting the funds out of your HSA. "
https://www.hsaedge.com/2014/12/05/can-you-cash-out-an-hsa/
If you encounter a financial emergency before age 65, then you can withdraw HSA money for any reason. However, the IRS will penalize it heavily (20%) in addition to the income taxes you'll have to pay. That's even more than the 10% penalty you would have to pay on an early withdrawal from a 401(k) or other retirement plan. So an early withdrawal for non-qualified health expenses is not something you should plan on doing, but it is another way in which these plans are flexible.