Hydrogen storage is an urgent issue for mobile applications, to overcome this issue solid materials have a potential role for hydrogen storage applications. Moreover, the perovskite hydride materials have been extensively investigated for improvement in the field of hydrogen storage. However, this work is focused on the computational study of XAlH3 (X: Na, Mg) perovskite-type hydrides for different physical properties and hydrogen storage applications. Both materials were found thermodynamically, and mechanically stable from the negative formation energy and elastic properties. They exhibited cubic phases with computed lattice constants are 3.827 Å and 3.752 Å, respectively. The electronic properties indicated that both compounds have a metallic nature, and found the high contribution of Al-p state, and H-1s state near the Fermi level. However, the Hirshfeld net charge analysis detected, that charge transfer from Al and X (Na, Mg) atoms to H atoms. Furthermore, the metallic hydrides have promised candidates for hydrogen storage applications. Both compounds have observed non-magnetic behavior with zero magnetic moments. Elastic constants were calculated to determine the mechanical stability of the compounds, it was found that MgAlH3 is harder than NaAlH3, and it exhibited that higher Bulk, Shear, and Young's modulus. The Poisson's, and Pugh's (G/B) ratios suggested that ionic boning of the atoms, additionally, Pugh's ratio (B/G) and Cauchy pressure (Cp) confirmed that NaAlH3 ductile and MgAlH3 is brittle behavior. Besides this, Optical properties were determined for both compounds including the dielectric function, conductivity, refractive index, absorption, and loss function. It is found that the MgAlH3 compound optical more suitable than NaAlH3 due to calculated optical factors promised and both compounds are undertaken for solar cells, optoelectronics, and energy storage applications. Finally, the computed hydrogen storage capacity for NaAlH3 and MgAlH3 compounds are 6.01 wt%, and 5.56 wt% respectively. These results revealed that both have the potential materials for hydrogen storage, but NaAlH3 unique material to fulfill the US-DOE criteria of 2020.