Traditionally, the wavelength range where room-temperature, infrared optoelectronic devices operate is tuned by changing the composition of semiconductor alloys during growth, but it is fixed once fabricated. Although the wide, dynamic, and reversible tuning of the operating wavelength range after fabrication is a highly desirable feature in various applications, no such platform has been developed yet in the infrared range. Here, we present black phosphorus (bP) as an ideal candidate for infrared optoelectronics with dynamically variable spectrum, owing to the extraordinary sensitivity of its bandgap to strain, covering from 2.3 to 4.7 μm. We leverage this property to develop dynamic spectrum infrared detectors and light-emitting diodes with the performance exceeding their counterparts based on narrow bandgap III-V and II-VI materials. Furthermore, by exploiting the dynamic spectrum mid-infrared electroluminescence, multiplexed non-dispersive infrared (NDIR) gas sensing is demonstrated for selective detection of multiple gases with a single light source.