<?xml version="1.0" encoding="UTF-8"?><edgarSubmission xmlns="http://www.sec.gov/edgar/ownership" xmlns:ns2="http://www.sec.gov/edgar/common">
    <headerData>
        <submissionType>144</submissionType>
        <filerInfo>
            <filer>
                <filerCredentials>
                    <cik>0001650692</cik>
                    <ccc>XXXXXXXX</ccc>
                </filerCredentials>
            </filer>
            <liveTestFlag>LIVE</liveTestFlag>



        </filerInfo>
    </headerData>
    <formData>
        <issuerInfo>
            <issuerCik>0001069878</issuerCik>
            <issuerName>TREX COMPANY INC.</issuerName>
            <secFileNumber>001-14649</secFileNumber>
            <issuerAddress>
                <ns2:street1>2500 Trex Way</ns2:street1>
                <ns2:city>Winchester</ns2:city>
                <ns2:stateOrCountry>VA</ns2:stateOrCountry>
                <ns2:zipCode>22601</ns2:zipCode>
            </issuerAddress>
            <issuerContactPhone>(540) 542-6300</issuerContactPhone>
            <nameOfPersonForWhoseAccountTheSecuritiesAreToBeSold>BRYAN FAIRBANKS</nameOfPersonForWhoseAccountTheSecuritiesAreToBeSold>
            <relationshipsToIssuer>
                <relationshipToIssuer>Officer</relationshipToIssuer>
                <relationshipToIssuer>Director</relationshipToIssuer>
            </relationshipsToIssuer>
        </issuerInfo>
        <securitiesInformation>
            <securitiesClassTitle>Common</securitiesClassTitle>
            <brokerOrMarketmakerDetails>
                <name>Morgan Stanley Smith Barney LLC Executive Financial Services</name>
                <address>
                    <ns2:street1>1 New York Plaza</ns2:street1>
                    <ns2:street2>8th Floor</ns2:street2>
                    <ns2:city>New York</ns2:city>
                    <ns2:stateOrCountry>NY</ns2:stateOrCountry>
                    <ns2:zipCode>10004</ns2:zipCode>
                </address>
            </brokerOrMarketmakerDetails>
            <noOfUnitsSold>6164</noOfUnitsSold>
            <aggregateMarketValue>591412.99</aggregateMarketValue>
            <noOfUnitsOutstanding>108623606</noOfUnitsOutstanding>
            <approxSaleDate>03/04/2024</approxSaleDate>
            <securitiesExchangeName>NYSE</securitiesExchangeName>
        </securitiesInformation>
        <securitiesToBeSold>
            <securitiesClassTitle>Common</securitiesClassTitle>
            <acquiredDate>02/19/2022</acquiredDate>
            <natureOfAcquisitionTransaction>Restricted stock vesting under a registered plan</natureOfAcquisitionTransaction>
            <nameOfPersonfromWhomAcquired>Issuer</nameOfPersonfromWhomAcquired>
            <isGiftTransaction>N</isGiftTransaction>
            <amountOfSecuritiesAcquired>768</amountOfSecuritiesAcquired>
            <paymentDate>02/19/2022</paymentDate>
            <natureOfPayment>Services Rendered</natureOfPayment>
        </securitiesToBeSold>
        <securitiesToBeSold>
            <securitiesClassTitle>Common</securitiesClassTitle>
            <acquiredDate>02/17/2022</acquiredDate>
            <natureOfAcquisitionTransaction>Restricted stock vesting under a registered plan</natureOfAcquisitionTransaction>
            <nameOfPersonfromWhomAcquired>Issuer</nameOfPersonfromWhomAcquired>
            <isGiftTransaction>N</isGiftTransaction>
            <amountOfSecuritiesAcquired>938</amountOfSecuritiesAcquired>
            <paymentDate>02/17/2022</paymentDate>
            <natureOfPayment>Services Rendered</natureOfPayment>
        </securitiesToBeSold>
        <securitiesToBeSold>
            <securitiesClassTitle>Common</securitiesClassTitle>
            <acquiredDate>02/13/2022</acquiredDate>
            <natureOfAcquisitionTransaction>Restricted stock vesting under a registered plan</natureOfAcquisitionTransaction>
            <nameOfPersonfromWhomAcquired>Issuer</nameOfPersonfromWhomAcquired>
            <isGiftTransaction>N</isGiftTransaction>
            <amountOfSecuritiesAcquired>920</amountOfSecuritiesAcquired>
            <paymentDate>02/13/2022</paymentDate>
            <natureOfPayment>Services Rendered</natureOfPayment>
        </securitiesToBeSold>
        <securitiesToBeSold>
            <securitiesClassTitle>Common</securitiesClassTitle>
            <acquiredDate>02/19/2021</acquiredDate>
            <natureOfAcquisitionTransaction>Restricted stock vesting under a registered plan</natureOfAcquisitionTransaction>
            <nameOfPersonfromWhomAcquired>Issuer</nameOfPersonfromWhomAcquired>
            <isGiftTransaction>N</isGiftTransaction>
            <amountOfSecuritiesAcquired>769</amountOfSecuritiesAcquired>
            <paymentDate>02/19/2021</paymentDate>
            <natureOfPayment>Services Rendered</natureOfPayment>
        </securitiesToBeSold>
        <securitiesToBeSold>
            <securitiesClassTitle>Common</securitiesClassTitle>
            <acquiredDate>02/17/2021</acquiredDate>
            <natureOfAcquisitionTransaction>Restricted stock vesting under a registered plan</natureOfAcquisitionTransaction>
            <nameOfPersonfromWhomAcquired>Issuer</nameOfPersonfromWhomAcquired>
            <isGiftTransaction>N</isGiftTransaction>
            <amountOfSecuritiesAcquired>1265</amountOfSecuritiesAcquired>
            <paymentDate>02/17/2021</paymentDate>
            <natureOfPayment>Services Rendered</natureOfPayment>
        </securitiesToBeSold>
        <securitiesToBeSold>
            <securitiesClassTitle>Common</securitiesClassTitle>
            <acquiredDate>02/17/2021</acquiredDate>
            <natureOfAcquisitionTransaction>Restricted stock vesting under a registered plan</natureOfAcquisitionTransaction>
            <nameOfPersonfromWhomAcquired>Issuer</nameOfPersonfromWhomAcquired>
            <isGiftTransaction>N</isGiftTransaction>
            <amountOfSecuritiesAcquired>1504</amountOfSecuritiesAcquired>
            <paymentDate>02/17/2021</paymentDate>
            <natureOfPayment>Services Rendered</natureOfPayment>
        </securitiesToBeSold>
        <nothingToReportFlagOnSecuritiesSoldInPast3Months>Y</nothingToReportFlagOnSecuritiesSoldInPast3Months>
        <noticeSignature>
            <noticeDate>03/04/2024</noticeDate>
            <planAdoptionDates/>
            <signature>/s/ Bryan Horix Fairbanks</signature>
        </noticeSignature>
    </formData>
</edgarSubmission>
[{"type": "144", "sequence": "1", "filename": "primary_doc.xml", "secsgml_size_bytes": 6426}]
144
0001650692
XXXXXXXX
LIVE
0001069878
TREX COMPANY INC.
001-14649
2500 Trex Way
Winchester
VA
22601
(540) 542-6300
BRYAN FAIRBANKS
Officer
Director
Common
Morgan Stanley Smith Barney LLC Executive Financial Services
1 New York Plaza
8th Floor
New York
NY
10004
6164
591412.99
108623606
03/04/2024
NYSE
Common
02/19/2022
Restricted stock vesting under a registered plan
Issuer
N
768
02/19/2022
Services Rendered
Common
02/17/2022
Restricted stock vesting under a registered plan
Issuer
N
938
02/17/2022
Services Rendered
Common
02/13/2022
Restricted stock vesting under a registered plan
Issuer
N
920
02/13/2022
Services Rendered
Common
02/19/2021
Restricted stock vesting under a registered plan
Issuer
N
769
02/19/2021
Services Rendered
Common
02/17/2021
Restricted stock vesting under a registered plan
Issuer
N
1265
02/17/2021
Services Rendered
Common
02/17/2021
Restricted stock vesting under a registered plan
Issuer
N
1504
02/17/2021
Services Rendered
Y
03/04/2024
/s/ Bryan Horix Fairbanks