Cementite -type carbides are of interest for magnetocaloric applications owing to temperature -or pressure -induced magnetic phase transition. Here, using first -principles calculations, we investigate the magnetism and the magnetic phase transition in iron carbide (Fe 3 C) with the substitution of Cr atoms at Fe sites with the strain effect. The presence of Cr atoms is found to give rise to a second -order magnetic phase transition from a ferromagnetic phase for Fe 3 C to a nonmagnetic phase in chromium carbide (Cr 3 C). While the ternary Fe 2 CrC and Cr 2 FeC compounds prefer the ferrimagnetic ground state, the magnitudes of both the Fe and the Cr spin moments, which are antiparallel in orientation, decrease as x increases in Fe 3−x Cr x C (x = 0, 1, 2, and 3).Furthermore, the fixed spin -moment calculations indicate that the magnetization of Fe 3−x Cr x C compounds can be delicately altered via the strain effect and that the magnetic -nonmagnetic phase transition occurs at an early stage of Cr substitution, x = 2.