In this work, we used the first-principles calculation based on density functional theory to investigate the effect of carbon substitution on structural, electronic, and optical properties of the MgSiP2 compound. Our calculations for the lattice constants show that both a and c decrease when the C atoms increasingly replace Si atoms in MgSiP2, however, the bulk modulus is found to be increasing. The calculated negative values of the formation energy (E-f) reveal that all MgSi1-xCxP2 alloys are thermodynamically stables. In addition, the substitution of the C atoms leads to a reduction of the value of the band-gap to 1.51 eV, 1.47 eV, and 1.30 eV for x = 0.25, 0.5 and, 0.75 respectively, these values have been calculated using the TB-mBJ approximation. We have calculated also the optical properties and the results show that the average absorption coefficient of MgSi1-xCxP2 alloys is improved in the visible light region (alpha similar to 10(5) cm(-1)). Therefore, the band-gap values and the high absorption coefficient (alpha similar to 10(5) cm(-1)) make MgSi1-xCxP2 alloys a promising candidate for photovoltaic applications. (C) 2020 Elsevier B.V. All rights reserved.