Thin films of MgxTi1−x show an optical black state upon hydrogenation. We calculate the dielectric function and the optical properties of MgxTi1−xH2, x=0.5, 0.75, and 0.875 using first-principles density-functional theory. We argue that the black state is an intrinsic property of these compounds, unlike similar optical phenomena observed in other metal hydride films. The structures of MgxTi1−xH2 are represented either by simple ordered or quasirandom structures. The density of states has a broad peak at the Fermi level, composed of Ti d states; hence, both interband and intraband transitions contribute to the optical response. Ordered structures have a plasma frequency of ~3 eV. The plasma frequency drops below 1 eV in disordered structures...