The popularity of confections laced with marijuana has caught many health officials by surprise. Pot edibles took off in 2014, the first year of recreational sales in Colorado, when nearly five million individual items were sold to patients and adult users.

Demand in Colorado and Washington State has spawned a stunning assortment of snacks and sweets, from Mondo’s sugar-free vegan bars to Dixie Edibles’ white chocolate peppermint squares.

Today consumers 21 and older can legally buy pot edibles in those two states; soon adults in Oregon and Alaska will join them. Pot edibles are available to medical users in at least a half dozen of the 23 states with medical marijuana programs.

Edibles make sense for marijuana entrepreneurs. In the past, marijuana buds were sold, and the rest of the plant was usually discarded. But with an extraction machine, makers of edible products can use the entire plant.

“In a world where THC becomes inexpensive, you would like to differentiate your product from other people’s products in ways that allow you to maintain a higher profit margin,” said Jonathan Caulkins, a co-author of “Marijuana Legalization,” who has studied black markets for cocaine and marijuana. “Edibles offer some opportunities for that.”

Buyers may not realize that the psychoactive effects of eating marijuana, which are largely due to a chemical called tetrahydrocannabinol, or THC, are much more unpredictable than smoking it. An edible can take one to three hours to produce its maximal high, while smoking takes minutes. Inexperienced consumers easily eat too much, winding up severely impaired.

Moreover, the effects of consumption can vary dramatically for each person from day to day, depending on what else is in the stomach, said Kari L. Franson, an associate professor of clinical pharmacy at the University of Colorado. “Compare that to smoking — within minutes you have a maximum effect,” she said. “It’s much easier to control.”