A variety of fiber-optic temperature sensors based on inline Mach–Zehnder interferometry (MZI) have been implemented for their ease of fabrication and cost efficiency, but it is difficult to control the length of the sensing area (i.e. the fiber section with sensitivity). Herein, we develop a new temperature sensor based on inline MZI by connecting two single-mode fibers (SMFs) with different mode-field diameters and by applying a load to one of the SMFs. The fiber section between the connector and the load operates as the sensing area, the length of which can be dynamically controlled by changing the load position.