The principle of leading lights is simple: by having two lights ashore - one at a high (rear) location and the other at a low (front) location, a ship approaching a channel observes the two lights and when they are in line - one above the other - the ships steams straight ahead knowing that it is sailing in the deepest water.
Of course, it is well known that rivers and estuaries are subject to silting and changes in the depth of water as sand or mud moves with time. This is usually taken care of by moving one of the lights. If the geographical area is one in which frequent changes occur, one of the lights (often the front one) is actually mounted on a track so that it can be easily moved.
Sometimes coloured sectors are used on lights to serve the same purpose. A white light is shown over a sector where the passage is safe and if the ship strays off the line, the light changes to red. Sometimes a green light may be used to indicate the safe channel. These are called sectored lights (see the bottom image).