By LIZ WESTON

Building wealth has gotten harder for most people in recent years. But the habits that can make you rich haven’t changed. It boils down to this: putting aside money, regularly and consistently, that can be invested for your future. You have to leave that money alone to grow, which means you also need an emergency fund. And you must be careful with debt, because the wrong kinds can erode your wealth rather than build it.

It’s a simple formula but one that’s become increasingly hard to implement as incomes stagnate and prices rise. A shocking number of American households — nearly half, by the Federal Reserve’s last count — don’t have enough savings to cover an unexpected $400 expense. Our inability to save has contributed to a 21 percent decline in household median net worth between 1998, the year median incomes peaked in America, and 2013, the last year for which Fed stats are available.

Hardest-hit are households in the lower middle class, which in 2013 meant incomes from $23,300 to $40,499. Their net worth fell by half.

Creating wealth is more difficult when you don’t have the economy behind you lifting your income, but it’s still possible. Here are the habits that people who build wealth use:

THEY PAY THEMSELVES FIRST: If you have nothing saved, start. You don’t need to have several months’ worth of expenses set aside, at least not yet: $500 is enough for now. That will cover many minor emergencies that might otherwise add to your debt.

Put aside something, anything, into an emergency fund every single paycheck. Pay the minimums on your credit cards and student loans and mortgages if that’s the only way to get a little breathing room. Make the transfers automatic, so they happen before you see the money and are tempted to spend it.

THEY INVEST FOR RETIREMENT: If there’s one thing every 20-something should be doing, it’s contributing to a retirement fund. (See “The Smartest Financial Decision You’ll Ever Make “) There’s no better time to put money aside than when you have decades ahead of you for that money to grow.

Those who start early have a much easier time of it: To retire with 60 percent of current income, someone starting at age 25 needs to put aside 6.4 percent of his pay. A 45-year- old would need to save 19.4 percent.

Even if you got a late start, you still need to save and invest. Most people have to stop working eventually, and even a small cushion can help you have a more comfortable retirement.

Oh, and you need to have most of your port- folio in equities, such as stock mutual funds and stock exchange traded funds. The financial crisis and continuing stock market volatility scared many people into keeping their money in low-risk investments, but that’s no way to get ahead. You need the kind of investment growth that can outpace inflation, and that’s what stocks offer.

THEY’RE SMART ABOUT DEBT: Moderate amounts of student loan debt can help you get an education that boosts your in- come. A reasonably sized mortgage can help you build equity in a home. Otherwise, you need to be cautious about adding new debts and vigilant about getting rid of any toxic debt that’s weighing you down.

Payday loans, auto title loans and credit card debt are among the biggest wealth- killers. If you have so much of this debt that you cannot pay it off in five years — while staying afloat with food and shelter — you should be talking with a bankruptcy attorney or credit counselor.

Otherwise, you need to target this debt for extinction. It may take years to dig yourself out, but keep chipping away. You’ll gain financial flexibility and, even better, lose the ever-present worry that comes with overwhelming debt.

Having some wealth doesn’t mean you stop worrying, of course. Even millionaires don’t feel like they’re out of the woods. Six out of ten people with $1 million to $5 mil- lion in assets said one major setback, such as a lost job or a stock market crash, could have a major impact on their lifestyle, ac- cording to a survey by investment bank UBS.

As you move away from a paycheck-to- paycheck life, though, you’re getting financially stronger. You’re better able to weather setbacks and you’ll have assets, such as stocks and a home, that can grow in value during good times. Even if you never make it to millionaire status, you can build a decent net worth that means a more comfortable life.