<?xml version='1.0' encoding='utf-8'?>
<FilingSummary>
  <Version>3.23.1</Version>
  <ProcessingTime/>
  <ReportFormat>html</ReportFormat>
  <ContextCount>506</ContextCount>
  <ElementCount>591</ElementCount>
  <EntityCount>1</EntityCount>
  <FootnotesReported>true</FootnotesReported>
  <SegmentCount>138</SegmentCount>
  <ScenarioCount>0</ScenarioCount>
  <TuplesReported>false</TuplesReported>
  <UnitCount>8</UnitCount>
  <MyReports>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R1.htm</HtmlFileName>
      <LongName>00090 - Document - Document and Entity Information</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DocumentDocumentAndEntityInformation</Role>
      <ShortName>Document and Entity Information</ShortName>
      <MenuCategory>Cover</MenuCategory>
      <Position>1</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R2.htm</HtmlFileName>
      <LongName>00100 - Statement - CONSOLIDATED BALANCE SHEETS</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/StatementConsolidatedBalanceSheets</Role>
      <ShortName>CONSOLIDATED BALANCE SHEETS</ShortName>
      <MenuCategory>Statements</MenuCategory>
      <Position>2</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R3.htm</HtmlFileName>
      <LongName>00105 - Statement - CONSOLIDATED BALANCE SHEETS (Parenthetical)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/StatementConsolidatedBalanceSheetsParenthetical</Role>
      <ShortName>CONSOLIDATED BALANCE SHEETS (Parenthetical)</ShortName>
      <MenuCategory>Statements</MenuCategory>
      <Position>3</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R4.htm</HtmlFileName>
      <LongName>00200 - Statement - CONSOLIDATED STATEMENTS OF COMPREHENSIVE INCOME (LOSS)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/StatementConsolidatedStatementsOfComprehensiveIncomeLoss</Role>
      <ShortName>CONSOLIDATED STATEMENTS OF COMPREHENSIVE INCOME (LOSS)</ShortName>
      <MenuCategory>Statements</MenuCategory>
      <Position>4</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R5.htm</HtmlFileName>
      <LongName>00205 - Statement - CONSOLIDATED STATEMENTS OF COMPREHENSIVE INCOME (LOSS) (Parenthetical)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/StatementConsolidatedStatementsOfComprehensiveIncomeLossParenthetical</Role>
      <ShortName>CONSOLIDATED STATEMENTS OF COMPREHENSIVE INCOME (LOSS) (Parenthetical)</ShortName>
      <MenuCategory>Statements</MenuCategory>
      <Position>5</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R6.htm</HtmlFileName>
      <LongName>00300 - Statement - CONSOLIDATED STATEMENTS OF CHANGES IN SHAREHOLDERS' EQUITY</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/StatementConsolidatedStatementsOfChangesInShareholdersEquity</Role>
      <ShortName>CONSOLIDATED STATEMENTS OF CHANGES IN SHAREHOLDERS' EQUITY</ShortName>
      <MenuCategory>Statements</MenuCategory>
      <Position>6</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R7.htm</HtmlFileName>
      <LongName>00400 - Statement - CONSOLIDATED STATEMENTS OF CASH FLOWS</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/StatementConsolidatedStatementsOfCashFlows</Role>
      <ShortName>CONSOLIDATED STATEMENTS OF CASH FLOWS</ShortName>
      <MenuCategory>Statements</MenuCategory>
      <Position>7</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R8.htm</HtmlFileName>
      <LongName>10101 - Disclosure - Organization and principal activities</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureOrganizationAndPrincipalActivities</Role>
      <ShortName>Organization and principal activities</ShortName>
      <MenuCategory>Notes</MenuCategory>
      <Position>8</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R9.htm</HtmlFileName>
      <LongName>10201 - Disclosure - Summary of significant accounting policies</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureSummaryOfSignificantAccountingPolicies</Role>
      <ShortName>Summary of significant accounting policies</ShortName>
      <MenuCategory>Notes</MenuCategory>
      <Position>9</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R10.htm</HtmlFileName>
      <LongName>10301 - Disclosure - Fair value of assets and liabilities</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureFairValueOfAssetsAndLiabilities</Role>
      <ShortName>Fair value of assets and liabilities</ShortName>
      <MenuCategory>Notes</MenuCategory>
      <Position>10</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R11.htm</HtmlFileName>
      <LongName>10401 - Disclosure - Prepaid expenses and other current assets</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosurePrepaidExpensesAndOtherCurrentAssets</Role>
      <ShortName>Prepaid expenses and other current assets</ShortName>
      <MenuCategory>Notes</MenuCategory>
      <Position>11</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R12.htm</HtmlFileName>
      <LongName>10501 - Disclosure - Deposits to institutional cooperators, net</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureDepositsToInstitutionalCooperatorsNet</Role>
      <ShortName>Deposits to institutional cooperators, net</ShortName>
      <MenuCategory>Notes</MenuCategory>
      <Position>12</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R13.htm</HtmlFileName>
      <LongName>10601 - Disclosure - Property and equipment, net</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosurePropertyAndEquipmentNet</Role>
      <ShortName>Property and equipment, net</ShortName>
      <MenuCategory>Notes</MenuCategory>
      <Position>13</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R14.htm</HtmlFileName>
      <LongName>10701 - Disclosure - Intangible assets, net</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureIntangibleAssetsNet</Role>
      <ShortName>Intangible assets, net</ShortName>
      <MenuCategory>Notes</MenuCategory>
      <Position>14</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R15.htm</HtmlFileName>
      <LongName>10801 - Disclosure - Short-term borrowings</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureShortTermBorrowings</Role>
      <ShortName>Short-term borrowings</ShortName>
      <MenuCategory>Notes</MenuCategory>
      <Position>15</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R16.htm</HtmlFileName>
      <LongName>10901 - Disclosure - Financial investments</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureFinancialInvestments</Role>
      <ShortName>Financial investments</ShortName>
      <MenuCategory>Notes</MenuCategory>
      <Position>16</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R17.htm</HtmlFileName>
      <LongName>11001 - Disclosure - Long-term investments</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureLongTermInvestments</Role>
      <ShortName>Long-term investments</ShortName>
      <MenuCategory>Notes</MenuCategory>
      <Position>17</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R18.htm</HtmlFileName>
      <LongName>11101 - Disclosure - Accrued expenses and other current liabilities</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureAccruedExpensesAndOtherCurrentLiabilities</Role>
      <ShortName>Accrued expenses and other current liabilities</ShortName>
      <MenuCategory>Notes</MenuCategory>
      <Position>18</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R19.htm</HtmlFileName>
      <LongName>11201 - Disclosure - Guarantee liabilities</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureGuaranteeLiabilities</Role>
      <ShortName>Guarantee liabilities</ShortName>
      <MenuCategory>Notes</MenuCategory>
      <Position>19</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R20.htm</HtmlFileName>
      <LongName>11301 - Disclosure - Related party balances and transactions</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureRelatedPartyBalancesAndTransactions</Role>
      <ShortName>Related party balances and transactions</ShortName>
      <MenuCategory>Notes</MenuCategory>
      <Position>20</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R21.htm</HtmlFileName>
      <LongName>11401 - Disclosure - Income taxes</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureIncomeTaxes</Role>
      <ShortName>Income taxes</ShortName>
      <MenuCategory>Notes</MenuCategory>
      <Position>21</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R22.htm</HtmlFileName>
      <LongName>11501 - Disclosure - Net income (loss) per share and net income (loss) attributable to common stockholders</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureNetIncomeLossPerShareAndNetIncomeLossAttributableToCommonStockholders</Role>
      <ShortName>Net income (loss) per share and net income (loss) attributable to common stockholders</ShortName>
      <MenuCategory>Notes</MenuCategory>
      <Position>22</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R23.htm</HtmlFileName>
      <LongName>11601 - Disclosure - Share-based compensation</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureShareBasedCompensation</Role>
      <ShortName>Share-based compensation</ShortName>
      <MenuCategory>Notes</MenuCategory>
      <Position>23</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R24.htm</HtmlFileName>
      <LongName>11701 - Disclosure - Statutory reserves and restricted net assets</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureStatutoryReservesAndRestrictedNetAssets</Role>
      <ShortName>Statutory reserves and restricted net assets</ShortName>
      <MenuCategory>Notes</MenuCategory>
      <Position>24</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R25.htm</HtmlFileName>
      <LongName>11801 - Disclosure - Commitments and contingencies</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureCommitmentsAndContingencies</Role>
      <ShortName>Commitments and contingencies</ShortName>
      <MenuCategory>Notes</MenuCategory>
      <Position>25</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R26.htm</HtmlFileName>
      <LongName>11901 - Disclosure - Subsequent events</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureSubsequentEvents</Role>
      <ShortName>Subsequent events</ShortName>
      <MenuCategory>Notes</MenuCategory>
      <Position>26</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R27.htm</HtmlFileName>
      <LongName>12001 - Disclosure - CONDENSED FINANCIAL INFORMATION OF PARENT COMPANY</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureCondensedFinancialInformationOfParentCompany</Role>
      <ShortName>CONDENSED FINANCIAL INFORMATION OF PARENT COMPANY</ShortName>
      <MenuCategory>Notes</MenuCategory>
      <Position>27</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R28.htm</HtmlFileName>
      <LongName>20202 - Disclosure - Summary of significant accounting policies (Policies)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureSummaryOfSignificantAccountingPoliciesPolicies</Role>
      <ShortName>Summary of significant accounting policies (Policies)</ShortName>
      <MenuCategory>Policies</MenuCategory>
      <Position>28</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R29.htm</HtmlFileName>
      <LongName>30103 - Disclosure - Organization and principal activities (Tables)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureOrganizationAndPrincipalActivitiesTables</Role>
      <ShortName>Organization and principal activities (Tables)</ShortName>
      <MenuCategory>Tables</MenuCategory>
      <ParentRole>http://ir.xiaoyinggroup.com/role/DisclosureOrganizationAndPrincipalActivities</ParentRole>
      <Position>29</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R30.htm</HtmlFileName>
      <LongName>30203 - Disclosure - Summary of significant accounting policies (Tables)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureSummaryOfSignificantAccountingPoliciesTables</Role>
      <ShortName>Summary of significant accounting policies (Tables)</ShortName>
      <MenuCategory>Tables</MenuCategory>
      <ParentRole>http://ir.xiaoyinggroup.com/role/DisclosureSummaryOfSignificantAccountingPolicies</ParentRole>
      <Position>30</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R31.htm</HtmlFileName>
      <LongName>30303 - Disclosure - Fair value of assets and liabilities (Tables)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureFairValueOfAssetsAndLiabilitiesTables</Role>
      <ShortName>Fair value of assets and liabilities (Tables)</ShortName>
      <MenuCategory>Tables</MenuCategory>
      <ParentRole>http://ir.xiaoyinggroup.com/role/DisclosureFairValueOfAssetsAndLiabilities</ParentRole>
      <Position>31</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R32.htm</HtmlFileName>
      <LongName>30403 - Disclosure - Prepaid expenses and other current assets (Tables)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosurePrepaidExpensesAndOtherCurrentAssetsTables</Role>
      <ShortName>Prepaid expenses and other current assets (Tables)</ShortName>
      <MenuCategory>Tables</MenuCategory>
      <ParentRole>http://ir.xiaoyinggroup.com/role/DisclosurePrepaidExpensesAndOtherCurrentAssets</ParentRole>
      <Position>32</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R33.htm</HtmlFileName>
      <LongName>30503 - Disclosure - Deposits to institutional cooperators, net (Tables)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureDepositsToInstitutionalCooperatorsNetTables</Role>
      <ShortName>Deposits to institutional cooperators, net (Tables)</ShortName>
      <MenuCategory>Tables</MenuCategory>
      <ParentRole>http://ir.xiaoyinggroup.com/role/DisclosureDepositsToInstitutionalCooperatorsNet</ParentRole>
      <Position>33</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R34.htm</HtmlFileName>
      <LongName>30603 - Disclosure - Property and equipment, net (Tables)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosurePropertyAndEquipmentNetTables</Role>
      <ShortName>Property and equipment, net (Tables)</ShortName>
      <MenuCategory>Tables</MenuCategory>
      <ParentRole>http://ir.xiaoyinggroup.com/role/DisclosurePropertyAndEquipmentNet</ParentRole>
      <Position>34</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R35.htm</HtmlFileName>
      <LongName>30703 - Disclosure - Intangible assets, net (Tables)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureIntangibleAssetsNetTables</Role>
      <ShortName>Intangible assets, net (Tables)</ShortName>
      <MenuCategory>Tables</MenuCategory>
      <ParentRole>http://ir.xiaoyinggroup.com/role/DisclosureIntangibleAssetsNet</ParentRole>
      <Position>35</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R36.htm</HtmlFileName>
      <LongName>30903 - Disclosure - Financial investments (Tables)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureFinancialInvestmentsTables</Role>
      <ShortName>Financial investments (Tables)</ShortName>
      <MenuCategory>Tables</MenuCategory>
      <ParentRole>http://ir.xiaoyinggroup.com/role/DisclosureFinancialInvestments</ParentRole>
      <Position>36</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R37.htm</HtmlFileName>
      <LongName>31003 - Disclosure - Long-term investments (Tables)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureLongTermInvestmentsTables</Role>
      <ShortName>Long-term investments (Tables)</ShortName>
      <MenuCategory>Tables</MenuCategory>
      <ParentRole>http://ir.xiaoyinggroup.com/role/DisclosureLongTermInvestments</ParentRole>
      <Position>37</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R38.htm</HtmlFileName>
      <LongName>31103 - Disclosure - Accrued expenses and other current liabilities (Tables)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureAccruedExpensesAndOtherCurrentLiabilitiesTables</Role>
      <ShortName>Accrued expenses and other current liabilities (Tables)</ShortName>
      <MenuCategory>Tables</MenuCategory>
      <ParentRole>http://ir.xiaoyinggroup.com/role/DisclosureAccruedExpensesAndOtherCurrentLiabilities</ParentRole>
      <Position>38</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R39.htm</HtmlFileName>
      <LongName>31203 - Disclosure - Guarantee liabilities (Tables)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureGuaranteeLiabilitiesTables</Role>
      <ShortName>Guarantee liabilities (Tables)</ShortName>
      <MenuCategory>Tables</MenuCategory>
      <ParentRole>http://ir.xiaoyinggroup.com/role/DisclosureGuaranteeLiabilities</ParentRole>
      <Position>39</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R40.htm</HtmlFileName>
      <LongName>31403 - Disclosure - Income taxes (Tables)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureIncomeTaxesTables</Role>
      <ShortName>Income taxes (Tables)</ShortName>
      <MenuCategory>Tables</MenuCategory>
      <ParentRole>http://ir.xiaoyinggroup.com/role/DisclosureIncomeTaxes</ParentRole>
      <Position>40</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R41.htm</HtmlFileName>
      <LongName>31503 - Disclosure - Net income (loss) per share and net income (loss) attributable to common stockholders (Tables)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureNetIncomeLossPerShareAndNetIncomeLossAttributableToCommonStockholdersTables</Role>
      <ShortName>Net income (loss) per share and net income (loss) attributable to common stockholders (Tables)</ShortName>
      <MenuCategory>Tables</MenuCategory>
      <ParentRole>http://ir.xiaoyinggroup.com/role/DisclosureNetIncomeLossPerShareAndNetIncomeLossAttributableToCommonStockholders</ParentRole>
      <Position>41</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R42.htm</HtmlFileName>
      <LongName>31603 - Disclosure - Share-based compensation (Tables)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureShareBasedCompensationTables</Role>
      <ShortName>Share-based compensation (Tables)</ShortName>
      <MenuCategory>Tables</MenuCategory>
      <ParentRole>http://ir.xiaoyinggroup.com/role/DisclosureShareBasedCompensation</ParentRole>
      <Position>42</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R43.htm</HtmlFileName>
      <LongName>32003 - Disclosure - CONDENSED FINANCIAL INFORMATION OF PARENT COMPANY (Tables)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureCondensedFinancialInformationOfParentCompanyTables</Role>
      <ShortName>CONDENSED FINANCIAL INFORMATION OF PARENT COMPANY (Tables)</ShortName>
      <MenuCategory>Tables</MenuCategory>
      <ParentRole>http://ir.xiaoyinggroup.com/role/DisclosureCondensedFinancialInformationOfParentCompany</ParentRole>
      <Position>43</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R44.htm</HtmlFileName>
      <LongName>40101 - Disclosure - Organization and principal activities (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureOrganizationAndPrincipalActivitiesDetails</Role>
      <ShortName>Organization and principal activities (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <ParentRole>http://ir.xiaoyinggroup.com/role/DisclosureOrganizationAndPrincipalActivitiesTables</ParentRole>
      <Position>44</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R45.htm</HtmlFileName>
      <LongName>40201 - Disclosure - Summary of significant accounting policies - Variable interest entity (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureSummaryOfSignificantAccountingPoliciesVariableInterestEntityDetails</Role>
      <ShortName>Summary of significant accounting policies - Variable interest entity (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>45</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R46.htm</HtmlFileName>
      <LongName>40202 - Disclosure - Summary of significant accounting policies - Consolidated Trusts (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureSummaryOfSignificantAccountingPoliciesConsolidatedTrustsDetails</Role>
      <ShortName>Summary of significant accounting policies - Consolidated Trusts (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>46</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R47.htm</HtmlFileName>
      <LongName>40203 - Disclosure - Summary of significant accounting policies - Revenue recognition (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureSummaryOfSignificantAccountingPoliciesRevenueRecognitionDetails</Role>
      <ShortName>Summary of significant accounting policies - Revenue recognition (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>47</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R48.htm</HtmlFileName>
      <LongName>40204 - Disclosure - Summary of significant accounting policies - Guarantee liabilities and Financial guarantee derivative (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureSummaryOfSignificantAccountingPoliciesGuaranteeLiabilitiesAndFinancialGuaranteeDerivativeDetails</Role>
      <ShortName>Summary of significant accounting policies - Guarantee liabilities and Financial guarantee derivative (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>48</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R49.htm</HtmlFileName>
      <LongName>40205 - Disclosure - Summary of significant accounting policies - Accounts receivable and contract assets and allowance for uncollectible accounts receivable and contract assets (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureSummaryOfSignificantAccountingPoliciesAccountsReceivableAndContractAssetsAndAllowanceForUncollectibleAccountsReceivableAndContractAssetsDetails</Role>
      <ShortName>Summary of significant accounting policies - Accounts receivable and contract assets and allowance for uncollectible accounts receivable and contract assets (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>49</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R50.htm</HtmlFileName>
      <LongName>40206 - Disclosure - Summary of significant accounting policies - Loan receivables from Xiaoying Credit Loans and Xiaoying Revolving Loans, net (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureSummaryOfSignificantAccountingPoliciesLoanReceivablesFromXiaoyingCreditLoansAndXiaoyingRevolvingLoansNetDetails</Role>
      <ShortName>Summary of significant accounting policies - Loan receivables from Xiaoying Credit Loans and Xiaoying Revolving Loans, net (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>50</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R51.htm</HtmlFileName>
      <LongName>40207 - Disclosure - Summary of significant accounting policies - Loan receivables from Xiaoying Credit Loans and Revolving Loans originated and retained by the Company (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureSummaryOfSignificantAccountingPoliciesLoanReceivablesFromXiaoyingCreditLoansAndRevolvingLoansOriginatedAndRetainedByCompanyDetails</Role>
      <ShortName>Summary of significant accounting policies - Loan receivables from Xiaoying Credit Loans and Revolving Loans originated and retained by the Company (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>51</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R52.htm</HtmlFileName>
      <LongName>40208 - Disclosure - Summary of significant accounting policies - Movement of provision for loan receivables from Xiaoying Credit Loans and Revolving Loans (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureSummaryOfSignificantAccountingPoliciesMovementOfProvisionForLoanReceivablesFromXiaoyingCreditLoansAndRevolvingLoansDetails</Role>
      <ShortName>Summary of significant accounting policies - Movement of provision for loan receivables from Xiaoying Credit Loans and Revolving Loans (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>52</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R53.htm</HtmlFileName>
      <LongName>40209 - Disclosure - Summary of significant accounting policies - Aging of loan receivables from Xiaoying Credit Loans and Revolving Loans (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureSummaryOfSignificantAccountingPoliciesAgingOfLoanReceivablesFromXiaoyingCreditLoansAndRevolvingLoansDetails</Role>
      <ShortName>Summary of significant accounting policies - Aging of loan receivables from Xiaoying Credit Loans and Revolving Loans (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>53</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R54.htm</HtmlFileName>
      <LongName>40210 - Disclosure - Summary of significant accounting policies - Loan receivable from Xiaoying Housing Loans, net (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureSummaryOfSignificantAccountingPoliciesLoanReceivableFromXiaoyingHousingLoansNetDetails</Role>
      <ShortName>Summary of significant accounting policies - Loan receivable from Xiaoying Housing Loans, net (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>54</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R55.htm</HtmlFileName>
      <LongName>40211 - Disclosure - Summary of significant accounting policies - Property and equipment, net, Intangible assets and Impairment long-lived assets (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureSummaryOfSignificantAccountingPoliciesPropertyAndEquipmentNetIntangibleAssetsAndImpairmentLongLivedAssetsDetails</Role>
      <ShortName>Summary of significant accounting policies - Property and equipment, net, Intangible assets and Impairment long-lived assets (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>55</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R56.htm</HtmlFileName>
      <LongName>40212 - Disclosure - Summary of significant accounting policies - Others (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureSummaryOfSignificantAccountingPoliciesOthersDetails</Role>
      <ShortName>Summary of significant accounting policies - Others (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <ParentRole>http://ir.xiaoyinggroup.com/role/DisclosureSummaryOfSignificantAccountingPoliciesTables</ParentRole>
      <Position>56</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R57.htm</HtmlFileName>
      <LongName>40213 - Disclosure - Summary of significant accounting policies - Leases (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureSummaryOfSignificantAccountingPoliciesLeasesDetails</Role>
      <ShortName>Summary of significant accounting policies - Leases (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <ParentRole>http://ir.xiaoyinggroup.com/role/DisclosureSummaryOfSignificantAccountingPoliciesTables</ParentRole>
      <Position>57</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R58.htm</HtmlFileName>
      <LongName>40214 - Disclosure - Summary of significant accounting policies - Certain risks and concentrations (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureSummaryOfSignificantAccountingPoliciesCertainRisksAndConcentrationsDetails</Role>
      <ShortName>Summary of significant accounting policies - Certain risks and concentrations (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>58</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R59.htm</HtmlFileName>
      <LongName>40301 - Disclosure - Fair value of assets and liabilities - Financial Instruments Recorded at Fair Value on a Recurring Basis (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureFairValueOfAssetsAndLiabilitiesFinancialInstrumentsRecordedAtFairValueOnRecurringBasisDetails</Role>
      <ShortName>Fair value of assets and liabilities - Financial Instruments Recorded at Fair Value on a Recurring Basis (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>59</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R60.htm</HtmlFileName>
      <LongName>40302 - Disclosure - Fair value of assets and liabilities - Asset of financial guarantee derivative movements (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureFairValueOfAssetsAndLiabilitiesAssetOfFinancialGuaranteeDerivativeMovementsDetails</Role>
      <ShortName>Fair value of assets and liabilities - Asset of financial guarantee derivative movements (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>60</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R61.htm</HtmlFileName>
      <LongName>40303 - Disclosure - Fair value of assets and liabilities - Liability of financial guarantee derivative movements (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureFairValueOfAssetsAndLiabilitiesLiabilityOfFinancialGuaranteeDerivativeMovementsDetails</Role>
      <ShortName>Fair value of assets and liabilities - Liability of financial guarantee derivative movements (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>61</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R62.htm</HtmlFileName>
      <LongName>40304 - Disclosure - Fair value of assets and liabilities - Xiaoying card loan products and Significant unobservable inputs (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureFairValueOfAssetsAndLiabilitiesXiaoyingCardLoanProductsAndSignificantUnobservableInputsDetails</Role>
      <ShortName>Fair value of assets and liabilities - Xiaoying card loan products and Significant unobservable inputs (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>62</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R63.htm</HtmlFileName>
      <LongName>40305 - Disclosure - Fair value of assets and liabilities - Loans, Payables to investors at fair value (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureFairValueOfAssetsAndLiabilitiesLoansPayablesToInvestorsAtFairValueDetails</Role>
      <ShortName>Fair value of assets and liabilities - Loans, Payables to investors at fair value (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>63</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R64.htm</HtmlFileName>
      <LongName>40401 - Disclosure - Prepaid expenses and other current assets (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosurePrepaidExpensesAndOtherCurrentAssetsDetails</Role>
      <ShortName>Prepaid expenses and other current assets (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <ParentRole>http://ir.xiaoyinggroup.com/role/DisclosurePrepaidExpensesAndOtherCurrentAssetsTables</ParentRole>
      <Position>64</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R65.htm</HtmlFileName>
      <LongName>40402 - Disclosure - Prepaid expenses and other current assets - Additional information (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosurePrepaidExpensesAndOtherCurrentAssetsAdditionalInformationDetails</Role>
      <ShortName>Prepaid expenses and other current assets - Additional information (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>65</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R66.htm</HtmlFileName>
      <LongName>40403 - Disclosure - Prepaid expenses and other current assets - Movement of the allowances for the credit losses (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosurePrepaidExpensesAndOtherCurrentAssetsMovementOfAllowancesForCreditLossesDetails</Role>
      <ShortName>Prepaid expenses and other current assets - Movement of the allowances for the credit losses (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>66</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R67.htm</HtmlFileName>
      <LongName>40501 - Disclosure - Deposits to institutional cooperators, net (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureDepositsToInstitutionalCooperatorsNetDetails</Role>
      <ShortName>Deposits to institutional cooperators, net (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <ParentRole>http://ir.xiaoyinggroup.com/role/DisclosureDepositsToInstitutionalCooperatorsNetTables</ParentRole>
      <Position>67</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R68.htm</HtmlFileName>
      <LongName>40502 - Disclosure - Deposits to institutional cooperators, net - Additional information (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureDepositsToInstitutionalCooperatorsNetAdditionalInformationDetails</Role>
      <ShortName>Deposits to institutional cooperators, net - Additional information (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>68</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R69.htm</HtmlFileName>
      <LongName>40503 - Disclosure - Deposits to institutional cooperators, net - Movement of the provision (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureDepositsToInstitutionalCooperatorsNetMovementOfProvisionDetails</Role>
      <ShortName>Deposits to institutional cooperators, net - Movement of the provision (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>69</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R70.htm</HtmlFileName>
      <LongName>40601 - Disclosure - Property and equipment, net (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosurePropertyAndEquipmentNetDetails</Role>
      <ShortName>Property and equipment, net (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <ParentRole>http://ir.xiaoyinggroup.com/role/DisclosurePropertyAndEquipmentNetTables</ParentRole>
      <Position>70</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R71.htm</HtmlFileName>
      <LongName>40701 - Disclosure - Intangible assets, net (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureIntangibleAssetsNetDetails</Role>
      <ShortName>Intangible assets, net (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <ParentRole>http://ir.xiaoyinggroup.com/role/DisclosureIntangibleAssetsNetTables</ParentRole>
      <Position>71</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R72.htm</HtmlFileName>
      <LongName>40801 - Disclosure - Short-term borrowings (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureShortTermBorrowingsDetails</Role>
      <ShortName>Short-term borrowings (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <ParentRole>http://ir.xiaoyinggroup.com/role/DisclosureShortTermBorrowings</ParentRole>
      <Position>72</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R73.htm</HtmlFileName>
      <LongName>40901 - Disclosure - Financial investments (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureFinancialInvestmentsDetails</Role>
      <ShortName>Financial investments (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <ParentRole>http://ir.xiaoyinggroup.com/role/DisclosureFinancialInvestmentsTables</ParentRole>
      <Position>73</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R74.htm</HtmlFileName>
      <LongName>40902 - Disclosure - . Financial investments - Carrying value of investments in VC funds (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureFinancialInvestmentsCarryingValueOfInvestmentsInVcFundsDetails</Role>
      <ShortName>. Financial investments - Carrying value of investments in VC funds (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>74</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R75.htm</HtmlFileName>
      <LongName>40903 - Disclosure - Financial investments - Combined financial information for the VC funds (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureFinancialInvestmentsCombinedFinancialInformationForVcFundsDetails</Role>
      <ShortName>Financial investments - Combined financial information for the VC funds (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>75</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R76.htm</HtmlFileName>
      <LongName>40904 - Disclosure - Financial investments - Summary of investments measured at cost minus impairment, plus or minus observable price changes from orderly transactions of identical or similar investments of the same issuer (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureFinancialInvestmentsSummaryOfInvestmentsMeasuredAtCostMinusImpairmentPlusOrMinusObservablePriceChangesFromOrderlyTransactionsOfIdenticalOrSimilarInvestmentsOfSameIssuerDetails</Role>
      <ShortName>Financial investments - Summary of investments measured at cost minus impairment, plus or minus observable price changes from orderly transactions of identical or similar investments of the same issuer (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>76</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R77.htm</HtmlFileName>
      <LongName>40905 - Disclosure - Financial investments - Summary of investments in VC funds in the form of partnership measured at fair value (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureFinancialInvestmentsSummaryOfInvestmentsInVcFundsInFormOfPartnershipMeasuredAtFairValueDetails</Role>
      <ShortName>Financial investments - Summary of investments in VC funds in the form of partnership measured at fair value (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>77</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R78.htm</HtmlFileName>
      <LongName>41001 - Disclosure - Long-term investments - Combined financial information for the investee companies (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureLongTermInvestmentsCombinedFinancialInformationForInvesteeCompaniesDetails</Role>
      <ShortName>Long-term investments - Combined financial information for the investee companies (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>78</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R79.htm</HtmlFileName>
      <LongName>41002 - Disclosure - Long-term investments - Additional Information (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureLongTermInvestmentsAdditionalInformationDetails</Role>
      <ShortName>Long-term investments - Additional Information (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>79</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R80.htm</HtmlFileName>
      <LongName>41101 - Disclosure - Accrued expenses and other current liabilities (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureAccruedExpensesAndOtherCurrentLiabilitiesDetails</Role>
      <ShortName>Accrued expenses and other current liabilities (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <ParentRole>http://ir.xiaoyinggroup.com/role/DisclosureAccruedExpensesAndOtherCurrentLiabilitiesTables</ParentRole>
      <Position>80</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R81.htm</HtmlFileName>
      <LongName>41201 - Disclosure - Guarantee liabilities (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureGuaranteeLiabilitiesDetails</Role>
      <ShortName>Guarantee liabilities (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <ParentRole>http://ir.xiaoyinggroup.com/role/DisclosureGuaranteeLiabilitiesTables</ParentRole>
      <Position>81</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R82.htm</HtmlFileName>
      <LongName>41301 - Disclosure - Related party balances and transactions (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureRelatedPartyBalancesAndTransactionsDetails</Role>
      <ShortName>Related party balances and transactions (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <ParentRole>http://ir.xiaoyinggroup.com/role/DisclosureRelatedPartyBalancesAndTransactions</ParentRole>
      <Position>82</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R83.htm</HtmlFileName>
      <LongName>41401 - Disclosure - Income taxes - Tax rates (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureIncomeTaxesTaxRatesDetails</Role>
      <ShortName>Income taxes - Tax rates (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>83</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R84.htm</HtmlFileName>
      <LongName>41402 - Disclosure - Income taxes - Current and deferred component of income tax expense (benefit) (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureIncomeTaxesCurrentAndDeferredComponentOfIncomeTaxExpenseBenefitDetails</Role>
      <ShortName>Income taxes - Current and deferred component of income tax expense (benefit) (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>84</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R85.htm</HtmlFileName>
      <LongName>41403 - Disclosure - Income taxes - Pre-tax income (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureIncomeTaxesPreTaxIncomeDetails</Role>
      <ShortName>Income taxes - Pre-tax income (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>85</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R86.htm</HtmlFileName>
      <LongName>41404 - Disclosure - Income taxes - Reconciliation between the income taxes expense (benefit) computed by applying the PRC tax rate and the actual provision for income taxes (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureIncomeTaxesReconciliationBetweenIncomeTaxesExpenseBenefitComputedByApplyingPrcTaxRateAndActualProvisionForIncomeTaxesDetails</Role>
      <ShortName>Income taxes - Reconciliation between the income taxes expense (benefit) computed by applying the PRC tax rate and the actual provision for income taxes (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>86</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R87.htm</HtmlFileName>
      <LongName>41405 - Disclosure - Income taxes - Effect of Tax holiday and preferential tax rate (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureIncomeTaxesEffectOfTaxHolidayAndPreferentialTaxRateDetails</Role>
      <ShortName>Income taxes - Effect of Tax holiday and preferential tax rate (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>87</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R88.htm</HtmlFileName>
      <LongName>41406 - Disclosure - Income taxes - Components of the deferred tax assets and liabilities (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureIncomeTaxesComponentsOfDeferredTaxAssetsAndLiabilitiesDetails</Role>
      <ShortName>Income taxes - Components of the deferred tax assets and liabilities (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>88</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R89.htm</HtmlFileName>
      <LongName>41407 - Disclosure - Income taxes - Movement of the valuation allowance (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureIncomeTaxesMovementOfValuationAllowanceDetails</Role>
      <ShortName>Income taxes - Movement of the valuation allowance (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>89</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R90.htm</HtmlFileName>
      <LongName>41408 - Disclosure - Income taxes - Unrecognized tax benefit (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureIncomeTaxesUnrecognizedTaxBenefitDetails</Role>
      <ShortName>Income taxes - Unrecognized tax benefit (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>90</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R91.htm</HtmlFileName>
      <LongName>41501 - Disclosure - Net income (loss) per share and net income (loss) attributable to common stockholders (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureNetIncomeLossPerShareAndNetIncomeLossAttributableToCommonStockholdersDetails</Role>
      <ShortName>Net income (loss) per share and net income (loss) attributable to common stockholders (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <ParentRole>http://ir.xiaoyinggroup.com/role/DisclosureNetIncomeLossPerShareAndNetIncomeLossAttributableToCommonStockholdersTables</ParentRole>
      <Position>91</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R92.htm</HtmlFileName>
      <LongName>41502 - Disclosure - Net income (loss) per share and net income (loss) attributable to common stockholders - Anti-dilutive shares (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureNetIncomeLossPerShareAndNetIncomeLossAttributableToCommonStockholdersAntiDilutiveSharesDetails</Role>
      <ShortName>Net income (loss) per share and net income (loss) attributable to common stockholders - Anti-dilutive shares (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <ParentRole>http://ir.xiaoyinggroup.com/role/DisclosureNetIncomeLossPerShareAndNetIncomeLossAttributableToCommonStockholdersTables</ParentRole>
      <Position>92</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R93.htm</HtmlFileName>
      <LongName>41601 - Disclosure - Share-based compensation (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureShareBasedCompensationDetails</Role>
      <ShortName>Share-based compensation (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <ParentRole>http://ir.xiaoyinggroup.com/role/DisclosureShareBasedCompensationTables</ParentRole>
      <Position>93</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R94.htm</HtmlFileName>
      <LongName>41602 - Disclosure - Share-based compensation - Stock option valuation (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureShareBasedCompensationStockOptionValuationDetails</Role>
      <ShortName>Share-based compensation - Stock option valuation (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>94</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R95.htm</HtmlFileName>
      <LongName>41603 - Disclosure - Share-based compensation - Stock option activity (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureShareBasedCompensationStockOptionActivityDetails</Role>
      <ShortName>Share-based compensation - Stock option activity (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>95</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R96.htm</HtmlFileName>
      <LongName>41604 - Disclosure - Share-based compensation - Compensation cost (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureShareBasedCompensationCompensationCostDetails</Role>
      <ShortName>Share-based compensation - Compensation cost (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>96</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R97.htm</HtmlFileName>
      <LongName>41605 - Disclosure - Share-based compensation - Restricted stocks unit (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureShareBasedCompensationRestrictedStocksUnitDetails</Role>
      <ShortName>Share-based compensation - Restricted stocks unit (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>97</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R98.htm</HtmlFileName>
      <LongName>41701 - Disclosure - Statutory reserves and restricted net assets (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureStatutoryReservesAndRestrictedNetAssetsDetails</Role>
      <ShortName>Statutory reserves and restricted net assets (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <ParentRole>http://ir.xiaoyinggroup.com/role/DisclosureStatutoryReservesAndRestrictedNetAssets</ParentRole>
      <Position>98</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R99.htm</HtmlFileName>
      <LongName>41801 - Disclosure - Commitments and contingencies (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureCommitmentsAndContingenciesDetails</Role>
      <ShortName>Commitments and contingencies (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <ParentRole>http://ir.xiaoyinggroup.com/role/DisclosureCommitmentsAndContingencies</ParentRole>
      <Position>99</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R100.htm</HtmlFileName>
      <LongName>41901 - Disclosure - Subsequent events (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureSubsequentEventsDetails</Role>
      <ShortName>Subsequent events (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <ParentRole>http://ir.xiaoyinggroup.com/role/DisclosureSubsequentEvents</ParentRole>
      <Position>100</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R101.htm</HtmlFileName>
      <LongName>42001 - Disclosure - CONDENSED FINANCIAL INFORMATION OF PARENT COMPANY - BALANCE SHEETS (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureCondensedFinancialInformationOfParentCompanyBalanceSheetsDetails</Role>
      <ShortName>CONDENSED FINANCIAL INFORMATION OF PARENT COMPANY - BALANCE SHEETS (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>101</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R102.htm</HtmlFileName>
      <LongName>42002 - Disclosure - CONDENSED FINANCIAL INFORMATION OF PARENT COMPANY - STATEMENTS OF COMPREHENSIVE INCOME (LOSS) (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureCondensedFinancialInformationOfParentCompanyStatementsOfComprehensiveIncomeLossDetails</Role>
      <ShortName>CONDENSED FINANCIAL INFORMATION OF PARENT COMPANY - STATEMENTS OF COMPREHENSIVE INCOME (LOSS) (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>102</Position>
    </Report>
    <Report instance="xyf-20221231x20f.htm">
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <HtmlFileName>R103.htm</HtmlFileName>
      <LongName>42003 - Disclosure - CONDENSED FINANCIAL INFORMATION OF PARENT COMPANY - STATEMENT OF CASH FLOWS (Details)</LongName>
      <ReportType>Sheet</ReportType>
      <Role>http://ir.xiaoyinggroup.com/role/DisclosureCondensedFinancialInformationOfParentCompanyStatementOfCashFlowsDetails</Role>
      <ShortName>CONDENSED FINANCIAL INFORMATION OF PARENT COMPANY - STATEMENT OF CASH FLOWS (Details)</ShortName>
      <MenuCategory>Details</MenuCategory>
      <Position>103</Position>
    </Report>
    <Report>
      <IsDefault>false</IsDefault>
      <HasEmbeddedReports>false</HasEmbeddedReports>
      <LongName>All Reports</LongName>
      <ReportType>Book</ReportType>
      <ShortName>All Reports</ShortName>
    </Report>
  </MyReports>
  <Logs>
    <Log type="Warning">[dq-0542-Deprecated-Concept] Concept TreasuryStockShares in us-gaap/2022 used in 2 facts was deprecated in us-gaap/2023 as of 2023 and should not be used. xyf-20221231x20f.htm 191</Log>
    <Log type="Warning">[dq-0542-Deprecated-Concept] Concept TreasuryStockMember in us-gaap/2022 used in 6 facts was deprecated in us-gaap/2023 as of 2023 and should not be used. xyf-20221231x20f.htm 193</Log>
    <Log type="Warning">[dq-0542-Deprecated-Concept] Concept DueFromEmployeesCurrent in us-gaap/2022 used in 3 facts was deprecated in us-gaap/2023 as of 2023 and should not be used. xyf-20221231x20f.htm 234</Log>
    <Log type="Warning">[dq-0542-Deprecated-Concept] Concept InterestIncomeRelatedParty in us-gaap/2022 used in 4 facts was deprecated in us-gaap/2023 as of 2023 and should not be used. xyf-20221231x20f.htm 241</Log>
    <Log type="Warning">[dq-0542-Deprecated-Concept] Concept RevenueFromRelatedParties in us-gaap/2022 used in 5 facts was deprecated in us-gaap/2023 as of 2023 and should not be used. xyf-20221231x20f.htm 241</Log>
    <Log type="Warning">[ix-0514-Hidden-Fact-Eligible-For-Transform] WARN: 13 fact(s) appearing in ix:hidden were eligible for transformation: us-gaap:DebtInstrumentTerm, us-gaap:FiniteLivedIntangibleAssetUsefulLife, us-gaap:ShareBasedCompensationArrangementByShareBasedPaymentAwardAwardVestingPeriod1, us-gaap:SharebasedCompensationArrangementBySharebasedPaymentAwardExpirationPeriod, xyf:IncomeTaxStatuteOfLimitationsPeriodForTaxEvasion, xyf:NoticePeriodForTerminationOfAgreement, xyf:PeriodForCompensationInDefaultOfBorrowers, xyf:ShareBasedCompensationArrangementByShareBasedPaymentAwardOptionsExercisesInPeriodWeightedAverageRemainingContractualTerm, xyf:ShareBasedCompensationArrangementByShareBasedPaymentAwardOptionsForfeituresInPeriodWeightedAverageRemainingContractualTerm, xyf:ShareBasedCompensationArrangementByShareBasedPaymentAwardOptionsGrantsInPeriodWeightedAverageRemainingContractualTerm -  xyf-20221231x20f.htm 9</Log>
    <Log type="Warning">[ix-0514-Hidden-Fact-Not-Referenced] WARN: 11 fact(s) appearing in ix:hidden were not referenced by any -sec-ix-hidden style property: us-gaap:CommitmentsAndContingencies, us-gaap:OperatingLeaseLiabilityCurrentStatementOfFinancialPositionExtensibleList, us-gaap:OperatingLeaseLiabilityNoncurrentStatementOfFinancialPositionExtensibleList, us-gaap:OperatingLeaseLiabilityStatementOfFinancialPositionExtensibleList, us-gaap:OperatingLeaseRightOfUseAssetStatementOfFinancialPositionExtensibleList -  xyf-20221231x20f.htm 9</Log>
  </Logs>
  <InputFiles>
    <File doctype="20-F" original="xyf-20221231x20f.htm">xyf-20221231x20f.htm</File>
    <File>xyf-20221231.xsd</File>
    <File>xyf-20221231_cal.xml</File>
    <File>xyf-20221231_def.xml</File>
    <File>xyf-20221231_lab.xml</File>
    <File>xyf-20221231_pre.xml</File>
    <File>xyf-20221231xex12d1.htm</File>
    <File>xyf-20221231xex12d2.htm</File>
    <File>xyf-20221231xex13d1.htm</File>
    <File>xyf-20221231xex13d2.htm</File>
    <File>xyf-20221231xex15d1.htm</File>
    <File>xyf-20221231xex4d27.htm</File>
    <File>xyf-20221231xex4d28.htm</File>
    <File>xyf-20221231xex4d29.htm</File>
    <File>xyf-20221231xex4d30.htm</File>
    <File>xyf-20221231xex8d1.htm</File>
    <File>xyf-20221231xex99d2.htm</File>
    <File>xyf-20221231xex99d3.htm</File>
  </InputFiles>
  <SupplementalFiles>
    <File>xyf-20221231x20f005.jpg</File>
    <File>xyf-20221231x20f006.jpg</File>
    <File>xyf-20221231x20f010.jpg</File>
  </SupplementalFiles>
  <BaseTaxonomies>
    <BaseTaxonomy items="5">http://fasb.org/srt/2022</BaseTaxonomy>
    <BaseTaxonomy items="2021">http://fasb.org/us-gaap/2022</BaseTaxonomy>
    <BaseTaxonomy items="50">http://xbrl.sec.gov/dei/2022</BaseTaxonomy>
  </BaseTaxonomies>
  <HasPresentationLinkbase>true</HasPresentationLinkbase>
  <HasCalculationLinkbase>true</HasCalculationLinkbase>
</FilingSummary>
