A water purifier or other liquid dispenser may sense a height of the inlet of a container accurately through an infrared transmitter and an infrared receiver that are disposed at different positions of a water discharge module moving vertically. Additionally, in the water purifier, the water discharge module may discharge purified water at a point spaced a certain distance apart from the inlet of the container, based on infrared sensing, thereby preventing the inlet of the container from contacting the lower surface of the water discharge module.