The sensitivity of gravitational-wave detectors is limited by the mechanical loss associated with the amorphous coatings of the detectors' mirrors. Amorphous silicon has higher refraction index and lower mechanical loss than current high-index coatings, but its optical absorption at the wavelength used for the detectors is at present large. The addition of hydrogen to the amorphous silicon network reduces both optical absorption and mechanical loss for films prepared under a range of conditions at all measured wavelengths and temperatures, with a particularly large effect on films grown at room temperature. The uptake of hydrogen is greatest in the films grown at room temperature, but still below 1.5 at.% H, which show an ultralow optical absorption (below 10 ppm) measured at 2000 nm for 500-nm-thick films. These results show that hydrogenation is a promising strategy to reduce both optical absorption and mechanical loss in amorphous silicon, and may enable fabrication of mirror coatings for gravitational-wave detectors with improved sensitivity.