For years, millennials looked at owning a home as a distant fantasy. Student debt and a weak job market seemed to conspire to keep this generation stuck in their parents’ basements, if not permanently locked out of the housing market.

But as millennials find better-paying jobs, start families and begin searching for their first homes, they’re encountering an unfortunate reality: Just as they’re finally ready to buy, the housing market has the fewest homes available for sale on record. And those that are for sale are increasingly priced at values inaccessible to first-time buyers.

As a result, the housing market is booming for those with cash to spare — but not for millennials looking to own their first home.

Keona and Cameron Morrison, both 31 and with a combined income of $150,000, have been looking to buy in Los Angeles for two years.

“There’s stuff that comes [on the market]; literally, a couple days later, it’s pending,” Keona said. “It’s crazy.”

Teree Warren, a 31-year-old forensic scientist who grew up in Prince George’s County, isn’t faring much better in the Dallas-Fort Worth area.

“The houses go so quickly,” she said.

Overall millennials are falling behind other generations in homeownership, with first-time home buyers, who usually consist of 40 percent of the market, stuck at 34 percent.

[Opinion: Millennials aren’t buying homes. Good for them.]

That could become damaging to this generation’s future prosperity. Housing experts say homeownership remains one of the primary ways for the middle class to build wealth, despite the ups and downs of the past decade. And with mortgage rates beginning to creep up, millennials who have to wait to buy could miss out on historically low rates.

“Owning a home for a longer period of time creates more wealth,” said Christopher E. Herbert, managing director of the Harvard Joint Center for Housing Studies. “If you shrink that amount of time, you’re going to shrink how much wealth it creates.”

For Keona Morrison, the challenge of finding a home feels deeply personal.

“I feel like if there were more African Americans owning homes, we could set our children up for greater success,” she said. “It’s all about having that leverage. . . . I guess what homeownership means to me is just having your own place, having something you can fall back on.”

Improvement since recession

For years after the recession, most millennials couldn’t afford to even consider entering the housing market. Many were saddled with student debt, and the labor market wasn’t friendly even to young college grads, contributing to the stereotypical image of the barista with a bachelor’s degree.

But as the economy has improved, so have millennials’ fortunes.

The most recent employment data shows that the percentage of 25-to-34-year-olds in the labor force is the largest in eight years. This group has also recently begun to enjoy stark wage gains. Recent census data showed that in 2015, millennials’ incomes jumped 7 percent, far more than most other groups’. Seventy-two percent of millennials rate their personal financial situation as fairly good or very good in 2016, up substantially from three years earlier, according to a recent Harvard Institute of Politics poll.

In a stronger financial position, more millennials are starting families. The census projects that household formation will average about 1.5 million per year through 2020, up from the 900,000 annual average in the past five years.

But when looking to leverage some of their newfound financial strength to buy a home for themselves or their new families, millennials are finding a less optimistic picture.

[How policymakers can help more millennials become homeowners]

The National Association of Realtors reported in December that the number of homes for sale nationally had fallen to its lowest level since the organization began keeping track of inventory in 1999. Inventory picked up slightly in January, but the year-over-year number of listings has dropped for 20 consecutive months.

At the current sales pace, the supply of homes would be exhausted in 3½ months. (A healthy market has about a six-month supply of homes for sale.) More than a fifth of housing markets across the country have a three-month supply of homes, double what it was two years ago, according to Pro Teck Valuation Services, a real estate analytics company.

Entry-level housing, the homes millennials can most afford, has been particularly scarce. The expensive D.C. region has less than a 90-days supply of condos costing between $400,000 and $600,000. In the Dallas area, where Warren is looking to buy, barely a one-month supply of those homes are for sale.

Warren said a friend of hers listed his house on a Thursday at 10 a.m. By noon, he had six appointments. By the end of the day, he had 10. His house sold on Sunday for far more than the asking price.

“It is very nerve-racking, the pressure that you have to make a decision very quickly,” Warren said.

[All the reasons it’s so much harder to buy a home than it was for your parents]

At the same time, the dearth of homes for sale is driving up prices, making homeownership even more difficult for millennials who do find a home to buy. Home values have hit an all-time high three months in a row.

Competition is the biggest factor driving up prices. The Morrisons have lost out on two homes, getting outbid by $10,000 each time. Now they are waiting to hear on a triplex three miles east of Inglewood.

“This last one my husband offered $10,000 over asking, and I was like, ‘Why did you do that?’ ” Keona said. “He’s like, ‘We lost out on the other two by offering asking.’ ”

Factors affecting inventory

Several factors have contributed to the insufficient inventory. The amount of time a homeowner stays in their home has grown from six years to an all-time high of 10 years. Some homeowners aren’t moving because they owe more on their mortgage than their home is worth. Others would like to sell but worry about finding their next home.

Most housing experts primarily blame low inventory on home builders, who scaled way back after the recession. Housing starts have slowly begun to rise, but construction remains well below healthy levels.

“The challenge is really adding inventory at the entry-level space,” said Robert Dietz, chief economist of the National Association of Home Builders. “Can builders do that at a cost that meets buyers’ expectations, given rising land development costs, rising wages and rising land costs?”

Some experts have suggested in recent years that millennials may not want to own homes. But surveys have consistently disproved that notion.

As bleak as home-buying prospects may seem for millennials, Harvard’s Herbert offers an optimistic perspective. Baby boomers who came of age in the early 1980s similarly faced a negative climate because of a double-dip recession and double-digit mortgage rates. But then homeownership rates and housing prices boomed in the 1990s.

“That group started out on a slower trajectory, then caught up,” he said. “When you’re young, you have some time to make up for a slower start, depending on what happens with the broader economy.”