<?xml version='1.0' encoding='utf-8'?>
<FilingSummary>
  <Version>3.24.1.u1</Version>
  <ProcessingTime/>
  <ReportFormat>html</ReportFormat>
  <ContextCount>180</ContextCount>
  <ElementCount>246</ElementCount>
  <EntityCount>1</EntityCount>
  <FootnotesReported>false</FootnotesReported>
  <SegmentCount>74</SegmentCount>
  <ScenarioCount>0</ScenarioCount>
  <TuplesReported>false</TuplesReported>
  <UnitCount>5</UnitCount>
  <MyReports>
    <Report instance="xfor-20240331.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R1.htm</HtmlFileName>
      <LongName>0000001 - Document - Cover Page</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://www.x4pharma.com/role/CoverPage</Role>
      <ShortName>Cover Page</ShortName>
      <MenuCategory>Cover</MenuCategory>
      <Position>1</Position>
    </Report>
    <Report instance="xfor-20240331.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R2.htm</HtmlFileName>
      <LongName>0000002 - Statement - CONDENSED CONSOLIDATED BALANCE SHEETS</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://www.x4pharma.com/role/CONDENSEDCONSOLIDATEDBALANCESHEETS</Role>
      <ShortName>CONDENSED CONSOLIDATED BALANCE SHEETS</ShortName>
      <MenuCategory>Statements</MenuCategory>
      <Position>2</Position>
    </Report>
    <Report instance="xfor-20240331.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R3.htm</HtmlFileName>
      <LongName>0000003 - Statement - CONDENSED CONSOLIDATED BALANCE SHEETS (Parenthetical)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://www.x4pharma.com/role/CONDENSEDCONSOLIDATEDBALANCESHEETSParenthetical</Role>
      <ShortName>CONDENSED CONSOLIDATED BALANCE SHEETS (Parenthetical)</ShortName>
      <MenuCategory>Statements</MenuCategory>
      <Position>3</Position>
    </Report>
    <Report instance="xfor-20240331.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R4.htm</HtmlFileName>
      <LongName>0000004 - Statement - CONDENSED CONSOLIDATED STATEMENTS OF OPERATIONS AND COMPREHENSIVE LOSS</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://www.x4pharma.com/role/CONDENSEDCONSOLIDATEDSTATEMENTSOFOPERATIONSANDCOMPREHENSIVELOSS</Role>
      <ShortName>CONDENSED CONSOLIDATED STATEMENTS OF OPERATIONS AND COMPREHENSIVE LOSS</ShortName>
      <MenuCategory>Statements</MenuCategory>
      <Position>4</Position>
    </Report>
    <Report instance="xfor-20240331.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R5.htm</HtmlFileName>
      <LongName>0000005 - Statement - CONDENSED CONSOLIDATED STATEMENTS OF CONVERTIBLE PREFERRED STOCK, REDEEMABLE COMMON STOCK AND STOCKHOLDERS' EQUITY (DEFICIT)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://www.x4pharma.com/role/CONDENSEDCONSOLIDATEDSTATEMENTSOFCONVERTIBLEPREFERREDSTOCKREDEEMABLECOMMONSTOCKANDSTOCKHOLDERSEQUITYDEFICIT</Role>
      <ShortName>CONDENSED CONSOLIDATED STATEMENTS OF CONVERTIBLE PREFERRED STOCK, REDEEMABLE COMMON STOCK AND STOCKHOLDERS' EQUITY (DEFICIT)</ShortName>
      <MenuCategory>Statements</MenuCategory>
      <Position>5</Position>
    </Report>
    <Report instance="xfor-20240331.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R6.htm</HtmlFileName>
      <LongName>0000006 - Statement - CONDENSED CONSOLIDATED STATEMENTS OF CASH FLOWS</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://www.x4pharma.com/role/CONDENSEDCONSOLIDATEDSTATEMENTSOFCASHFLOWS</Role>
      <ShortName>CONDENSED CONSOLIDATED STATEMENTS OF CASH FLOWS</ShortName>
      <MenuCategory>Statements</MenuCategory>
      <Position>6</Position>
    </Report>
    <Report instance="xfor-20240331.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R7.htm</HtmlFileName>
      <LongName>0000007 - Disclosure - Nature of the Business and Basis of Presentation</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://www.x4pharma.com/role/NatureoftheBusinessandBasisofPresentation</Role>
      <ShortName>Nature of the Business and Basis of Presentation</ShortName>
      <MenuCategory>Notes</MenuCategory>
      <Position>7</Position>
    </Report>
    <Report instance="xfor-20240331.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R8.htm</HtmlFileName>
      <LongName>0000008 - Disclosure - Summary of Significant Accounting Policies</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://www.x4pharma.com/role/SummaryofSignificantAccountingPolicies</Role>
      <ShortName>Summary of Significant Accounting Policies</ShortName>
      <MenuCategory>Notes</MenuCategory>
      <Position>8</Position>
    </Report>
    <Report instance="xfor-20240331.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R9.htm</HtmlFileName>
      <LongName>0000009 - Disclosure - License, Collaboration, and Funding Agreements</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://www.x4pharma.com/role/LicenseCollaborationandFundingAgreements</Role>
      <ShortName>License, Collaboration, and Funding Agreements</ShortName>
      <MenuCategory>Notes</MenuCategory>
      <Position>9</Position>
    </Report>
    <Report instance="xfor-20240331.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R10.htm</HtmlFileName>
      <LongName>0000010 - Disclosure - Fair Value of Financial Assets and Liabilities</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://www.x4pharma.com/role/FairValueofFinancialAssetsandLiabilities</Role>
      <ShortName>Fair Value of Financial Assets and Liabilities</ShortName>
      <MenuCategory>Notes</MenuCategory>
      <Position>10</Position>
    </Report>
    <Report instance="xfor-20240331.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R11.htm</HtmlFileName>
      <LongName>0000011 - Disclosure - Property and Equipment, Net</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://www.x4pharma.com/role/PropertyandEquipmentNet</Role>
      <ShortName>Property and Equipment, Net</ShortName>
      <MenuCategory>Notes</MenuCategory>
      <Position>11</Position>
    </Report>
    <Report instance="xfor-20240331.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R12.htm</HtmlFileName>
      <LongName>0000012 - Disclosure - Accrued Expenses</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://www.x4pharma.com/role/AccruedExpenses</Role>
      <ShortName>Accrued Expenses</ShortName>
      <MenuCategory>Notes</MenuCategory>
      <Position>12</Position>
    </Report>
    <Report instance="xfor-20240331.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R13.htm</HtmlFileName>
      <LongName>0000013 - Disclosure - Long-Term Debt</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://www.x4pharma.com/role/LongTermDebt</Role>
      <ShortName>Long-Term Debt</ShortName>
      <MenuCategory>Notes</MenuCategory>
      <Position>13</Position>
    </Report>
    <Report instance="xfor-20240331.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R14.htm</HtmlFileName>
      <LongName>0000014 - Disclosure - Leases</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://www.x4pharma.com/role/Leases</Role>
      <ShortName>Leases</ShortName>
      <MenuCategory>Notes</MenuCategory>
      <Position>14</Position>
    </Report>
    <Report instance="xfor-20240331.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R15.htm</HtmlFileName>
      <LongName>0000015 - Disclosure - Commitment and Contingencies</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://www.x4pharma.com/role/CommitmentandContingencies</Role>
      <ShortName>Commitment and Contingencies</ShortName>
      <MenuCategory>Notes</MenuCategory>
      <Position>15</Position>
    </Report>
    <Report instance="xfor-20240331.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R16.htm</HtmlFileName>
      <LongName>0000016 - Disclosure - Common Stock Warrants</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://www.x4pharma.com/role/CommonStockWarrants</Role>
      <ShortName>Common Stock Warrants</ShortName>
      <MenuCategory>Notes</MenuCategory>
      <Position>16</Position>
    </Report>
    <Report instance="xfor-20240331.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R17.htm</HtmlFileName>
      <LongName>0000017 - Disclosure - Stock-Based Compensation</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://www.x4pharma.com/role/StockBasedCompensation</Role>
      <ShortName>Stock-Based Compensation</ShortName>
      <MenuCategory>Notes</MenuCategory>
      <Position>17</Position>
    </Report>
    <Report instance="xfor-20240331.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R18.htm</HtmlFileName>
      <LongName>0000018 - Disclosure - Income Taxes</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://www.x4pharma.com/role/IncomeTaxes</Role>
      <ShortName>Income Taxes</ShortName>
      <MenuCategory>Notes</MenuCategory>
      <Position>18</Position>
    </Report>
    <Report instance="xfor-20240331.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R19.htm</HtmlFileName>
      <LongName>0000019 - Disclosure - Net Loss per Share</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://www.x4pharma.com/role/NetLossperShare</Role>
      <ShortName>Net Loss per Share</ShortName>
      <MenuCategory>Notes</MenuCategory>
      <Position>19</Position>
    </Report>
    <Report instance="xfor-20240331.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R20.htm</HtmlFileName>
      <LongName>9954471 - Disclosure - Summary of Significant Accounting Policies (Policies)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://www.x4pharma.com/role/SummaryofSignificantAccountingPoliciesPolicies</Role>
      <ShortName>Summary of Significant Accounting Policies (Policies)</ShortName>
      <MenuCategory>Policies</MenuCategory>
      <ParentRole>http://www.x4pharma.com/role/SummaryofSignificantAccountingPolicies</ParentRole>
      <Position>20</Position>
    </Report>
    <Report instance="xfor-20240331.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R21.htm</HtmlFileName>
      <LongName>9954472 - Disclosure - Summary of Significant Accounting Policies (Tables)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://www.x4pharma.com/role/SummaryofSignificantAccountingPoliciesTables</Role>
      <ShortName>Summary of Significant Accounting Policies (Tables)</ShortName>
      <MenuCategory>Tables</MenuCategory>
      <ParentRole>http://www.x4pharma.com/role/SummaryofSignificantAccountingPolicies</ParentRole>
      <Position>21</Position>
    </Report>
    <Report instance="xfor-20240331.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R22.htm</HtmlFileName>
      <LongName>9954473 - Disclosure - Fair Value of Financial Assets and Liabilities (Tables)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://www.x4pharma.com/role/FairValueofFinancialAssetsandLiabilitiesTables</Role>
      <ShortName>Fair Value of Financial Assets and Liabilities (Tables)</ShortName>
      <MenuCategory>Tables</MenuCategory>
      <ParentRole>http://www.x4pharma.com/role/FairValueofFinancialAssetsandLiabilities</ParentRole>
      <Position>22</Position>
    </Report>
    <Report instance="xfor-20240331.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R23.htm</HtmlFileName>
      <LongName>9954474 - Disclosure - Property and Equipment, Net (Tables)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://www.x4pharma.com/role/PropertyandEquipmentNetTables</Role>
      <ShortName>Property and Equipment, Net (Tables)</ShortName>
      <MenuCategory>Tables</MenuCategory>
      <ParentRole>http://www.x4pharma.com/role/PropertyandEquipmentNet</ParentRole>
      <Position>23</Position>
    </Report>
    <Report instance="xfor-20240331.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R24.htm</HtmlFileName>
      <LongName>9954475 - Disclosure - Accrued Expenses (Tables)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://www.x4pharma.com/role/AccruedExpensesTables</Role>
      <ShortName>Accrued Expenses (Tables)</ShortName>
      <MenuCategory>Tables</MenuCategory>
      <ParentRole>http://www.x4pharma.com/role/AccruedExpenses</ParentRole>
      <Position>24</Position>
    </Report>
    <Report instance="xfor-20240331.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R25.htm</HtmlFileName>
      <LongName>9954476 - Disclosure - Long-Term Debt (Tables)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://www.x4pharma.com/role/LongTermDebtTables</Role>
      <ShortName>Long-Term Debt (Tables)</ShortName>
      <MenuCategory>Tables</MenuCategory>
      <ParentRole>http://www.x4pharma.com/role/LongTermDebt</ParentRole>
      <Position>25</Position>
    </Report>
    <Report instance="xfor-20240331.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R26.htm</HtmlFileName>
      <LongName>9954477 - Disclosure - Leases (Tables)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://www.x4pharma.com/role/LeasesTables</Role>
      <ShortName>Leases (Tables)</ShortName>
      <MenuCategory>Tables</MenuCategory>
      <ParentRole>http://www.x4pharma.com/role/Leases</ParentRole>
      <Position>26</Position>
    </Report>
    <Report instance="xfor-20240331.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R27.htm</HtmlFileName>
      <LongName>9954478 - Disclosure - Common Stock Warrants (Tables)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://www.x4pharma.com/role/CommonStockWarrantsTables</Role>
      <ShortName>Common Stock Warrants (Tables)</ShortName>
      <MenuCategory>Tables</MenuCategory>
      <ParentRole>http://www.x4pharma.com/role/CommonStockWarrants</ParentRole>
      <Position>27</Position>
    </Report>
    <Report instance="xfor-20240331.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R28.htm</HtmlFileName>
      <LongName>9954479 - Disclosure - Stock-Based Compensation (Tables)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://www.x4pharma.com/role/StockBasedCompensationTables</Role>
      <ShortName>Stock-Based Compensation (Tables)</ShortName>
      <MenuCategory>Tables</MenuCategory>
      <ParentRole>http://www.x4pharma.com/role/StockBasedCompensation</ParentRole>
      <Position>28</Position>
    </Report>
    <Report instance="xfor-20240331.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R29.htm</HtmlFileName>
      <LongName>9954480 - Disclosure - Net Loss per Share (Tables)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://www.x4pharma.com/role/NetLossperShareTables</Role>
      <ShortName>Net Loss per Share (Tables)</ShortName>
      <MenuCategory>Tables</MenuCategory>
      <ParentRole>http://www.x4pharma.com/role/NetLossperShare</ParentRole>
      <Position>29</Position>
    </Report>
    <Report instance="xfor-20240331.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R30.htm</HtmlFileName>
      <LongName>9954481 - Disclosure - Nature of the Business and Basis of Presentation - Additional Information (Detail)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://www.x4pharma.com/role/NatureoftheBusinessandBasisofPresentationAdditionalInformationDetail</Role>
      <ShortName>Nature of the Business and Basis of Presentation - Additional Information (Detail)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>30</Position>
    </Report>
    <Report instance="xfor-20240331.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R31.htm</HtmlFileName>
      <LongName>9954482 - Disclosure - Summary of Significant Accounting Policies - Schedule of Compensating Balance Arrangements (Detail)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://www.x4pharma.com/role/SummaryofSignificantAccountingPoliciesScheduleofCompensatingBalanceArrangementsDetail</Role>
      <ShortName>Summary of Significant Accounting Policies - Schedule of Compensating Balance Arrangements (Detail)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>31</Position>
    </Report>
    <Report instance="xfor-20240331.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R32.htm</HtmlFileName>
      <LongName>9954483 - Disclosure - Summary of Significant Accounting Policies - Schedule of Reconciliation of Cash, Cash Equivalents, and Restricted Cash (Detail)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://www.x4pharma.com/role/SummaryofSignificantAccountingPoliciesScheduleofReconciliationofCashCashEquivalentsandRestrictedCashDetail</Role>
      <ShortName>Summary of Significant Accounting Policies - Schedule of Reconciliation of Cash, Cash Equivalents, and Restricted Cash (Detail)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>32</Position>
    </Report>
    <Report instance="xfor-20240331.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R33.htm</HtmlFileName>
      <LongName>9954484 - Disclosure - License, Collaboration, and Funding Agreements - Additional Information (Detail)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://www.x4pharma.com/role/LicenseCollaborationandFundingAgreementsAdditionalInformationDetail</Role>
      <ShortName>License, Collaboration, and Funding Agreements - Additional Information (Detail)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>33</Position>
    </Report>
    <Report instance="xfor-20240331.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R34.htm</HtmlFileName>
      <LongName>9954485 - Disclosure - Fair Value of Financial Assets and Liabilities - Schedule of Assets and Liabilities Measured at Fair Value (Detail)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://www.x4pharma.com/role/FairValueofFinancialAssetsandLiabilitiesScheduleofAssetsandLiabilitiesMeasuredatFairValueDetail</Role>
      <ShortName>Fair Value of Financial Assets and Liabilities - Schedule of Assets and Liabilities Measured at Fair Value (Detail)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>34</Position>
    </Report>
    <Report instance="xfor-20240331.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R35.htm</HtmlFileName>
      <LongName>9954486 - Disclosure - Fair Value of Financial Assets and Liabilities - Debt Securities Available-for-Sale (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://www.x4pharma.com/role/FairValueofFinancialAssetsandLiabilitiesDebtSecuritiesAvailableforSaleDetails</Role>
      <ShortName>Fair Value of Financial Assets and Liabilities - Debt Securities Available-for-Sale (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>35</Position>
    </Report>
    <Report instance="xfor-20240331.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R36.htm</HtmlFileName>
      <LongName>9954487 - Disclosure - Fair Value of Financial Assets and Liabilities - Aggregate Fair Values Financial Instruments (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://www.x4pharma.com/role/FairValueofFinancialAssetsandLiabilitiesAggregateFairValuesFinancialInstrumentsDetails</Role>
      <ShortName>Fair Value of Financial Assets and Liabilities - Aggregate Fair Values Financial Instruments (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>36</Position>
    </Report>
    <Report instance="xfor-20240331.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R37.htm</HtmlFileName>
      <LongName>9954488 - Disclosure - Fair Value of Financial Assets and Liabilities - Narrative (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://www.x4pharma.com/role/FairValueofFinancialAssetsandLiabilitiesNarrativeDetails</Role>
      <ShortName>Fair Value of Financial Assets and Liabilities - Narrative (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>37</Position>
    </Report>
    <Report instance="xfor-20240331.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R38.htm</HtmlFileName>
      <LongName>9954489 - Disclosure - Fair Value of Financial Assets and Liabilities - Fair Value Assumptions (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://www.x4pharma.com/role/FairValueofFinancialAssetsandLiabilitiesFairValueAssumptionsDetails</Role>
      <ShortName>Fair Value of Financial Assets and Liabilities - Fair Value Assumptions (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>38</Position>
    </Report>
    <Report instance="xfor-20240331.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R39.htm</HtmlFileName>
      <LongName>9954490 - Disclosure - Property and Equipment, Net - Schedule of Property and Equipment, Net (Detail)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://www.x4pharma.com/role/PropertyandEquipmentNetScheduleofPropertyandEquipmentNetDetail</Role>
      <ShortName>Property and Equipment, Net - Schedule of Property and Equipment, Net (Detail)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>39</Position>
    </Report>
    <Report instance="xfor-20240331.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R40.htm</HtmlFileName>
      <LongName>9954491 - Disclosure - Property and Equipment, Net - Additional Information (Detail)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://www.x4pharma.com/role/PropertyandEquipmentNetAdditionalInformationDetail</Role>
      <ShortName>Property and Equipment, Net - Additional Information (Detail)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>40</Position>
    </Report>
    <Report instance="xfor-20240331.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R41.htm</HtmlFileName>
      <LongName>9954492 - Disclosure - Accrued Expenses - Schedule of Accrued Expenses (Detail)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://www.x4pharma.com/role/AccruedExpensesScheduleofAccruedExpensesDetail</Role>
      <ShortName>Accrued Expenses - Schedule of Accrued Expenses (Detail)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>41</Position>
    </Report>
    <Report instance="xfor-20240331.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R42.htm</HtmlFileName>
      <LongName>9954493 - Disclosure - Long-Term Debt - Summary of Long Term Debt (Detail)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://www.x4pharma.com/role/LongTermDebtSummaryofLongTermDebtDetail</Role>
      <ShortName>Long-Term Debt - Summary of Long Term Debt (Detail)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>42</Position>
    </Report>
    <Report instance="xfor-20240331.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R43.htm</HtmlFileName>
      <LongName>9954494 - Disclosure - Long Term Debt - Hercules Loan Agreement - Additional Information (Detail)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://www.x4pharma.com/role/LongTermDebtHerculesLoanAgreementAdditionalInformationDetail</Role>
      <ShortName>Long Term Debt - Hercules Loan Agreement - Additional Information (Detail)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>43</Position>
    </Report>
    <Report instance="xfor-20240331.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R44.htm</HtmlFileName>
      <LongName>9954495 - Disclosure - Long-Term Debt - Summary of Interest Expense (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://www.x4pharma.com/role/LongTermDebtSummaryofInterestExpenseDetails</Role>
      <ShortName>Long-Term Debt - Summary of Interest Expense (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>44</Position>
    </Report>
    <Report instance="xfor-20240331.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R45.htm</HtmlFileName>
      <LongName>9954496 - Disclosure - Long-Term Debt - Schedule of Future Principal Payments and the Final Payments Due (Detail)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://www.x4pharma.com/role/LongTermDebtScheduleofFuturePrincipalPaymentsandtheFinalPaymentsDueDetail</Role>
      <ShortName>Long-Term Debt - Schedule of Future Principal Payments and the Final Payments Due (Detail)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>45</Position>
    </Report>
    <Report instance="xfor-20240331.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R46.htm</HtmlFileName>
      <LongName>9954497 - Disclosure - Leases - Additional Information (Detail)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://www.x4pharma.com/role/LeasesAdditionalInformationDetail</Role>
      <ShortName>Leases - Additional Information (Detail)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>46</Position>
    </Report>
    <Report instance="xfor-20240331.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R47.htm</HtmlFileName>
      <LongName>9954498 - Disclosure - Leases - Schedule of Components of Lease Expense (Detail)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://www.x4pharma.com/role/LeasesScheduleofComponentsofLeaseExpenseDetail</Role>
      <ShortName>Leases - Schedule of Components of Lease Expense (Detail)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>47</Position>
    </Report>
    <Report instance="xfor-20240331.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R48.htm</HtmlFileName>
      <LongName>9954499 - Disclosure - Leases - Schedule of Maturities of Lease Liabilities (Detail)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://www.x4pharma.com/role/LeasesScheduleofMaturitiesofLeaseLiabilitiesDetail</Role>
      <ShortName>Leases - Schedule of Maturities of Lease Liabilities (Detail)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>48</Position>
    </Report>
    <Report instance="xfor-20240331.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R49.htm</HtmlFileName>
      <LongName>9954500 - Disclosure - Commitment and Contingencies - Additional Information (Detail)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://www.x4pharma.com/role/CommitmentandContingenciesAdditionalInformationDetail</Role>
      <ShortName>Commitment and Contingencies - Additional Information (Detail)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>49</Position>
    </Report>
    <Report instance="xfor-20240331.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R50.htm</HtmlFileName>
      <LongName>9954501 - Disclosure - Common Stock Warrants - Additional Information (Detail)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://www.x4pharma.com/role/CommonStockWarrantsAdditionalInformationDetail</Role>
      <ShortName>Common Stock Warrants - Additional Information (Detail)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>50</Position>
    </Report>
    <Report instance="xfor-20240331.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R51.htm</HtmlFileName>
      <LongName>9954502 - Disclosure - Common Stock Warrants - Summary of Outstanding Warrants to Purchase Shares of Common Stock (Detail)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://www.x4pharma.com/role/CommonStockWarrantsSummaryofOutstandingWarrantstoPurchaseSharesofCommonStockDetail</Role>
      <ShortName>Common Stock Warrants - Summary of Outstanding Warrants to Purchase Shares of Common Stock (Detail)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>51</Position>
    </Report>
    <Report instance="xfor-20240331.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R52.htm</HtmlFileName>
      <LongName>9954503 - Disclosure - Stock-Based Compensation - Additional Information (Detail)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://www.x4pharma.com/role/StockBasedCompensationAdditionalInformationDetail</Role>
      <ShortName>Stock-Based Compensation - Additional Information (Detail)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>52</Position>
    </Report>
    <Report instance="xfor-20240331.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R53.htm</HtmlFileName>
      <LongName>9954504 - Disclosure - Stock-Based Compensation - Schedule of Assumptions Used in Black-Scholes Option-Pricing Model to Determine Grant-date Fair Value of Stock Options Granted (Detail)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://www.x4pharma.com/role/StockBasedCompensationScheduleofAssumptionsUsedinBlackScholesOptionPricingModeltoDetermineGrantdateFairValueofStockOptionsGrantedDetail</Role>
      <ShortName>Stock-Based Compensation - Schedule of Assumptions Used in Black-Scholes Option-Pricing Model to Determine Grant-date Fair Value of Stock Options Granted (Detail)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>53</Position>
    </Report>
    <Report instance="xfor-20240331.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R54.htm</HtmlFileName>
      <LongName>9954505 - Disclosure - Stock-Based Compensation - Summary of Stock Option Activity (Detail)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://www.x4pharma.com/role/StockBasedCompensationSummaryofStockOptionActivityDetail</Role>
      <ShortName>Stock-Based Compensation - Summary of Stock Option Activity (Detail)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>54</Position>
    </Report>
    <Report instance="xfor-20240331.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R55.htm</HtmlFileName>
      <LongName>9954506 - Disclosure - Stock-Based Compensation - Restricted Stock Units (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://www.x4pharma.com/role/StockBasedCompensationRestrictedStockUnitsDetails</Role>
      <ShortName>Stock-Based Compensation - Restricted Stock Units (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>55</Position>
    </Report>
    <Report instance="xfor-20240331.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R56.htm</HtmlFileName>
      <LongName>9954507 - Disclosure - Stock-Based Compensation Summary of Stock-Based Compensation Expense Classification (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://www.x4pharma.com/role/StockBasedCompensationSummaryofStockBasedCompensationExpenseClassificationDetails</Role>
      <ShortName>Stock-Based Compensation Summary of Stock-Based Compensation Expense Classification (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>56</Position>
    </Report>
    <Report instance="xfor-20240331.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R57.htm</HtmlFileName>
      <LongName>9954508 - Disclosure - Income Taxes - Additional Information (Detail)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://www.x4pharma.com/role/IncomeTaxesAdditionalInformationDetail</Role>
      <ShortName>Income Taxes - Additional Information (Detail)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>57</Position>
    </Report>
    <Report instance="xfor-20240331.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R58.htm</HtmlFileName>
      <LongName>9954509 - Disclosure - Net Loss per Share - Summary of Basic and Diluted Net loss per Share Attributable to Common Stockholders (Detail)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://www.x4pharma.com/role/NetLossperShareSummaryofBasicandDilutedNetlossperShareAttributabletoCommonStockholdersDetail</Role>
      <ShortName>Net Loss per Share - Summary of Basic and Diluted Net loss per Share Attributable to Common Stockholders (Detail)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>58</Position>
    </Report>
    <Report instance="xfor-20240331.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R59.htm</HtmlFileName>
      <LongName>9954510 - Disclosure - Net Loss per Share - Additional Information (Detail)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://www.x4pharma.com/role/NetLossperShareAdditionalInformationDetail</Role>
      <ShortName>Net Loss per Share - Additional Information (Detail)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>59</Position>
    </Report>
    <Report instance="xfor-20240331.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R60.htm</HtmlFileName>
      <LongName>9954511 - Disclosure - Net Loss per Share - Schedule of Anti-dilutive Securities Excluded from Computation of Diluted Net Loss per Share Attributable to Common Stockholders (Detail)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://www.x4pharma.com/role/NetLossperShareScheduleofAntidilutiveSecuritiesExcludedfromComputationofDilutedNetLossperShareAttributabletoCommonStockholdersDetail</Role>
      <ShortName>Net Loss per Share - Schedule of Anti-dilutive Securities Excluded from Computation of Diluted Net Loss per Share Attributable to Common Stockholders (Detail)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>60</Position>
    </Report>
    <Report>
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <LongName>All Reports</LongName>
      <ReportType>Book</ReportType>
      <ShortName>All Reports</ShortName>
    </Report>
  </MyReports>
  <InputFiles>
    <File doctype="10-Q" isDefinitelyFs="true" isUsgaap="true" original="xfor-20240331.htm">xfor-20240331.htm</File>
    <File>xfor-20240331.xsd</File>
    <File>xfor-20240331_cal.xml</File>
    <File>xfor-20240331_def.xml</File>
    <File>xfor-20240331_lab.xml</File>
    <File>xfor-20240331_pre.xml</File>
  </InputFiles>
  <SupplementalFiles/>
  <BaseTaxonomies>
    <BaseTaxonomy items="493">http://fasb.org/us-gaap/2023</BaseTaxonomy>
    <BaseTaxonomy items="30">http://xbrl.sec.gov/dei/2023</BaseTaxonomy>
  </BaseTaxonomies>
  <HasPresentationLinkbase>true</HasPresentationLinkbase>
  <HasCalculationLinkbase>true</HasCalculationLinkbase>
</FilingSummary>
