Southern California may have beautiful beaches and sunsets, but looks can be deceiving.

The California real estate market comprising the Los Angeles, Long Beach and Anaheim area is the most polluted housing market in the U.S., with 321 ZIP Codes, or 99% of the market, recording high or very high levels of exposure to unhealthy air, polluted land or water plus, as if that weren’t enough, dangerous drug labs, according to the real estate research firm RealtyTrac.

The Irvine, Calif.–based firm analyzed man-made-hazard data from both the Environmental Protection Agency and the Drug Enforcement Agency in more than 7,700 ZIP Codes accounting for air quality (defined as days without significant carbon monoxide, sulfur dioxide and other pollutants in the air), EPA-identified “Superfund” cleanup sites, number of polluters, “brownfields” and former drug labs, to determine which real estate markets have the most toxins.

Air quality, Superfund sites — places deemed hazardous enough to warrant a cleanup operation led by the EPA — and polluters each accounted for 25% of the index. Brownfields — those more than 500,000 properties in the U.S. that have lingering hazardous materials,​such as abandoned gas stations or factories — and former drug labs each accounted for 12.5% of the total index.

The real estate market comprising Chicago, Naperville and Elgin, Ill., came in second in the RealtyTrac analysis, with 280, or 93% of ZIP Codes, in the market having high exposure to toxins and pollutants. The third most toxic real estate market was the Detroit, Dearborn and Warren markets in Michigan, with 94%, or 162 ZIP Codes, of the market with high or very high levels of environmental risk.

Overall, the top 12 metro areas with the highest percentage of ZIP Codes at high risk for man-made environmental hazards were Riverside–San Bernardino in Southern California; Akron, Ohio; Cleveland; Stockton, Calif.; Louisville, Ky.; Reading, Pa.; Toledo, Ohio; El Paso, Texas; Los Angeles; Kansas City, Mo.; Grand Rapids, Mich.; and Bakersfield, Calif.

About 25 million U.S. homes are in ZIP Codes at high risk or very high risk for man-made environmental hazards, RealtyTrac said — representing 38% of the 64 million homes in the 7,700 ZIP Codes analyzed. The combined estimated market value of the 25 million homes in high risk or very high risk areas was $6.9 trillion as of November 2015.

Man-made environmental disasters often wreak havoc on real estate valuations. The median sales price of homes in high-risk ZIP Codes for man-made environmental hazards was $251,106 in 2015 on average, 15% lower than the median sales price of $295,202 for homes in ZIP Codes with low or very low risk, RealtyTrac said.

“Buying a home in an area with low risk of manmade environmental hazards may not just be a good idea for health and safety reasons, it may also be good for financial reasons,” said Daren Blomquist, vice president at RealtyTrac. “Across the country, home prices in high-risk ZIP Codes were lower on average, and appreciation over the last 10 years slower when compared to home prices and 10-year appreciation in low risk ZIP Codes,” he said.

RealtyTrac noted the impact on one housing community after the Aliso Canyon natural-gas storage facility owned by Southern California Gas in the Los Angeles suburb of Porter Ranch, Calif., suffered a massive leak, spewing more than 97,000 metric tons of methane into the air and forcing families to evacuate their homes for as long as four months. (Five years earlier in San Bruno, Calif., just south of San Francisco, eight people had been killed when an aging 30-inch natural-gas pipeline operated by Pacific Gas & Electric ruptured, incinerating 35 homes)

In the three months following the gas leak in late October 2015, home sales in the Porter Ranch ZIP Code (91326) plunged 44% (twice the normal seasonal drop), while the share of all-cash sales spiked 50% during the same time period. Meanwhile, the median home sales price in Porter Ranch in the three months following the discovery of the gas leak dropped 1%, after climbing more than 30% in the three years since 2012, according to Zillow.com.

Almost at the same time as the Porter Ranch leak, in Flint, Mich., residents awoke to find their tap water undrinkable, having been poisoned by lead after a misguided series of decisions a year earlier by local and state and federal environmental officials to use the long-polluted Flint River as a water source.

Don’t miss:America’s water crisis is way bigger than Flint, Mich.

Read:Lead poisoning crisis sends Flint real-estate market tumbling

The water crisis led to the criminal charges filed this week against several state and local officials.

Median home sales prices in Flint had risen from a 10-year low in April 2014 to $46,700 in August of last year. But the water-poisoning crisis at the end of December dropped selling prices to $30,700, according to Zillow.com.