The tensile strength of loess is closely related to geological disasters. As an eco-friendly material, biopolymers have an excellent strengthening effect on the mechanical properties of soil. The effect of different initial dry densities and Xanthan gum (XG) contents on the microstructure and mechanical behavior of XG-treated loess was studied through a series of microscopic tests and splitting tensile tests based on the PIV technique. The results show that during the dehydration process, the XG became concentrated and agglomerated, forming bridge links between soil particles and covering the surface of soil particles. The XG-treated loess had a major concentration of micropores and mesopores, with greater peak intensities of pore size distribution curve than untreated loess. The load-displacement relation curves of specimens with different XG contents and initial dry densities showed strain-softening. The displacement vector field indicated that the primary cracks of specimens were radial vertical, the secondary cracks were well developed. With the increase of the XG content and initial dry density, the strain-softening phenomenon was more significant, the splitting tensile strength and brittleness of specimens were greater. XG treatment made the soils obtain stronger cementation and denser structure, which helped to increase strength and brittleness.