In this study, we have investigated the electronic and optical properties of half-Heusler NiXSn (X = Zr, Hf) compounds under pressure by means of first principles calculations. The generalized gradient approximation is used to model exchange-correlation effects. We have estimated a transition from indirect band gap to direct band gap at 50 and 127 GPa for NiZrSn and NiHfSn, respectively. We have also plotted the static dielectric constant versus pressure for both compounds. The obtained results are in agreement with the available experimental and theoretical data.