What happened

Shares of Trex (TREX -0.93%), the leading maker of alternative decking and railing products, were gaining after the company posted better-than-expected results in the first quarter.

As of 10:05 a.m. ET, the stock was up 9.7%.

So what

Trex's business is closely tied to the housing and home improvement market, and as the housing market has slowed, so has demand for its products.

As a result, revenue in the quarter fell 30% to $238.7 million, but that still edged out estimates at $237.4 million.

The company said the decrease in sales was due more to cautious purchase patterns in the face of a softening economy. It also sold off its Trex Commercial business, which accounted for about $12 million in sales in the quarter a year ago.

Despite that decline in revenue, gross margin was mostly steady at 39.6%, compared to 39.8% in the quarter a year ago, or 40.9% for just the comparable residential gross margin. 

On the bottom line, earnings before interest, taxes, depreciation, and amortization (EBITDA) fell from $105 million to $69 million, and earnings per share declined from $0.62 to $0.38, but that still beat expectations at $0.34.

Trex CEO Bryan Fairbanks said:

First-quarter results were broadly consistent with our plan, as channel inventory levels and market demand aligned with our expectations. Additionally, we strengthened our market leadership position and stimulated demand with innovative new products that meet the evolving needs of the marketplace.

Now what

Looking ahead, management forecast second-quarter sales in the $310 million to $320 million range, which was better than expectations at $306.8 million but still down 18.5% from the quarter a year ago. 

It also called for a full-year adjusted EBITDA margin of 26% to 27%, showing the company's ability to maintain strong profitability even in a difficult environment.

Comparisons should get easier in the second half of the year, which could support further gains in the stock.