<?xml version="1.0"?>
<ownershipDocument>

    <schemaVersion>X0607</schemaVersion>

    <documentType>3</documentType>

    <periodOfReport>2026-04-28</periodOfReport>

    <noSecuritiesOwned>0</noSecuritiesOwned>

    <issuer>
        <issuerCik>0001069878</issuerCik>
        <issuerName>TREX CO INC</issuerName>
        <issuerTradingSymbol>TREX</issuerTradingSymbol>
        <issuerForeignTradingSymbol></issuerForeignTradingSymbol>
    </issuer>

    <reportingOwner>
        <reportingOwnerId>
            <rptOwnerCik>0002132943</rptOwnerCik>
            <rptOwnerName>Lauer Zachary C.</rptOwnerName>
        </reportingOwnerId>
        <reportingOwnerAddress>
            <rptOwnerNonUSAddressFlag>false</rptOwnerNonUSAddressFlag>
            <rptOwnerStreet1>2500 TREX WAY</rptOwnerStreet1>
            <rptOwnerStreet2>C/O TREX COMPANY, INC.</rptOwnerStreet2>
            <rptOwnerCity>WINCHESTER</rptOwnerCity>
            <rptOwnerState>VA</rptOwnerState>
            <rptOwnerZipCode>22601</rptOwnerZipCode>
            <rptOwnerStateDescription></rptOwnerStateDescription>
        </reportingOwnerAddress>
        <reportingOwnerRelationship>
            <isOfficer>1</isOfficer>
            <officerTitle>SVP, Chief Operations Officer</officerTitle>
        </reportingOwnerRelationship>
    </reportingOwner>

    <nonDerivativeTable>
        <nonDerivativeHolding>
            <securityTitle>
                <value>Common Stock</value>
            </securityTitle>
            <postTransactionAmounts>
                <sharesOwnedFollowingTransaction>
                    <value>28187</value>
                    <footnoteId id="F1"/>
                </sharesOwnedFollowingTransaction>
            </postTransactionAmounts>
            <ownershipNature>
                <directOrIndirectOwnership>
                    <value>D</value>
                </directOrIndirectOwnership>
            </ownershipNature>
        </nonDerivativeHolding>
    </nonDerivativeTable>

    <derivativeTable>
        <derivativeHolding>
            <securityTitle>
                <value>Stock Appreciation Right</value>
            </securityTitle>
            <conversionOrExercisePrice>
                <value>50.83</value>
            </conversionOrExercisePrice>
            <exerciseDate>
                <value>2023-02-19</value>
                <footnoteId id="F2"/>
            </exerciseDate>
            <expirationDate>
                <value>2030-02-19</value>
            </expirationDate>
            <underlyingSecurity>
                <underlyingSecurityTitle>
                    <value>Common Stock</value>
                </underlyingSecurityTitle>
                <underlyingSecurityShares>
                    <value>2166</value>
                </underlyingSecurityShares>
            </underlyingSecurity>
            <ownershipNature>
                <directOrIndirectOwnership>
                    <value>D</value>
                </directOrIndirectOwnership>
            </ownershipNature>
        </derivativeHolding>
        <derivativeHolding>
            <securityTitle>
                <value>Stock Appreciation Right</value>
            </securityTitle>
            <conversionOrExercisePrice>
                <value>104.56</value>
            </conversionOrExercisePrice>
            <exerciseDate>
                <value>2024-02-17</value>
                <footnoteId id="F3"/>
            </exerciseDate>
            <expirationDate>
                <value>2031-02-17</value>
            </expirationDate>
            <underlyingSecurity>
                <underlyingSecurityTitle>
                    <value>Common Stock</value>
                </underlyingSecurityTitle>
                <underlyingSecurityShares>
                    <value>810</value>
                </underlyingSecurityShares>
            </underlyingSecurity>
            <ownershipNature>
                <directOrIndirectOwnership>
                    <value>D</value>
                </directOrIndirectOwnership>
            </ownershipNature>
        </derivativeHolding>
        <derivativeHolding>
            <securityTitle>
                <value>Stock Appreciation Right</value>
            </securityTitle>
            <conversionOrExercisePrice>
                <value>82.01</value>
            </conversionOrExercisePrice>
            <exerciseDate>
                <value>2025-03-01</value>
                <footnoteId id="F4"/>
            </exerciseDate>
            <expirationDate>
                <value>2032-02-23</value>
            </expirationDate>
            <underlyingSecurity>
                <underlyingSecurityTitle>
                    <value>Common Stock</value>
                </underlyingSecurityTitle>
                <underlyingSecurityShares>
                    <value>1338</value>
                </underlyingSecurityShares>
            </underlyingSecurity>
            <ownershipNature>
                <directOrIndirectOwnership>
                    <value>D</value>
                </directOrIndirectOwnership>
            </ownershipNature>
        </derivativeHolding>
        <derivativeHolding>
            <securityTitle>
                <value>Stock Appreciation Right</value>
            </securityTitle>
            <conversionOrExercisePrice>
                <value>56.80</value>
            </conversionOrExercisePrice>
            <exerciseDate>
                <value>2026-03-01</value>
                <footnoteId id="F5"/>
            </exerciseDate>
            <expirationDate>
                <value>2033-02-14</value>
            </expirationDate>
            <underlyingSecurity>
                <underlyingSecurityTitle>
                    <value>Common Stock</value>
                </underlyingSecurityTitle>
                <underlyingSecurityShares>
                    <value>2152</value>
                </underlyingSecurityShares>
            </underlyingSecurity>
            <ownershipNature>
                <directOrIndirectOwnership>
                    <value>D</value>
                </directOrIndirectOwnership>
            </ownershipNature>
        </derivativeHolding>
        <derivativeHolding>
            <securityTitle>
                <value>Stock Appreciation Right</value>
            </securityTitle>
            <conversionOrExercisePrice>
                <value>90.86</value>
            </conversionOrExercisePrice>
            <exerciseDate>
                <value>2027-03-01</value>
                <footnoteId id="F6"/>
            </exerciseDate>
            <expirationDate>
                <value>2034-02-19</value>
            </expirationDate>
            <underlyingSecurity>
                <underlyingSecurityTitle>
                    <value>Common Stock</value>
                </underlyingSecurityTitle>
                <underlyingSecurityShares>
                    <value>1522</value>
                </underlyingSecurityShares>
            </underlyingSecurity>
            <ownershipNature>
                <directOrIndirectOwnership>
                    <value>D</value>
                </directOrIndirectOwnership>
            </ownershipNature>
        </derivativeHolding>
        <derivativeHolding>
            <securityTitle>
                <value>Stock Appreciation Right</value>
            </securityTitle>
            <conversionOrExercisePrice>
                <value>67.33</value>
            </conversionOrExercisePrice>
            <exerciseDate>
                <value>2028-03-01</value>
                <footnoteId id="F7"/>
            </exerciseDate>
            <expirationDate>
                <value>2035-02-17</value>
            </expirationDate>
            <underlyingSecurity>
                <underlyingSecurityTitle>
                    <value>Common Stock</value>
                </underlyingSecurityTitle>
                <underlyingSecurityShares>
                    <value>2481</value>
                </underlyingSecurityShares>
            </underlyingSecurity>
            <ownershipNature>
                <directOrIndirectOwnership>
                    <value>D</value>
                </directOrIndirectOwnership>
            </ownershipNature>
        </derivativeHolding>
    </derivativeTable>

    <footnotes>
        <footnote id="F1">Includes 3,848 time-based restricted stock units that vest March 1, 2027; 3,264 time-based restricted stock units that vest March 1, 2028; 2,304 time-based restricted stock units that vest March 1, 2029; a target number of 4,509 performance-based restricted stock units that vest on March 1, 2027; a target number of 3,675 performance-based restricted stock units that vest on March 1, 2028; and a target number of 2,304 performance-based restricted stock units that vest on March 1, 2029. The number of performance-based restricted stock units set forth above is the target number of shares. The number of shares that will actually vest will be based upon performance against certain financial goals for the Company and will range from 0% to 200% of the target number of shares.</footnote>
        <footnote id="F2">This stock appreciation right became exercisable in three equal installments that occurred on February 19, 2021, February 19, 2022, and February 19, 2023.</footnote>
        <footnote id="F3">This stock appreciation right became exercisable in three equal installments that occurred on February 17, 2022, February 17, 2023, and February 17, 2024.</footnote>
        <footnote id="F4">This stock appreciation right became exercisable in three equal installments that occurred on March 1, 2023, March 1, 2024, and March 1, 2025.</footnote>
        <footnote id="F5">This stock appreciation right became exercisable in three equal installments that occurred on March 1, 2024, March 1, 2025, and March 1, 2026.</footnote>
        <footnote id="F6">This stock appreciation right vests in three equal annual installments; the first and second installments became exercisable on March 1, 2025 and March 1, 2026, respectively, and the third installment will become exercisable on March 1, 2027.</footnote>
        <footnote id="F7">This stock appreciation right vests in three equal annual installments; the first installment became exercisable on March 1, 2026, and the second and third installments will become exercisable on March 1, 2027 and March 1, 2028, respectively.</footnote>
    </footnotes>

    <ownerSignature>
        <signatureName>/s/ Amy M. Fernandez by power of attorney</signatureName>
        <signatureDate>2026-05-06</signatureDate>
    </ownerSignature>
</ownershipDocument>
