A tankless water heater, also known as an on-demand water heater, works by heating water directly as it passes through the unit, without the need for a storage tank. When a hot water tap is turned on, cold water enters the unit through an inlet pipe and is quickly heated either by a gas burner or an electric element. The heated water then flows out of the unit and to the desired faucet or fixture.