As used in cars, the gauge consists of two parts:
The sending unit usually uses a float connected to a variable resistor. When the tank is full, the resistor is set to its low resistance value. As the tank empties, the float drops and the slides a moving contact along the resistor, increasing its resistance, finally reaching its highest value when the tank is empty. In addition, when the resistance is at a certain point, it will also turn on a "low fuel" light on some vehicles.
Meanwhile, the indicator unit (usually mounted on the instrument panel) is measuring and displaying the amount of electrical current flowing through the sending unit. When the tank level is high and maximum current is flowing, the needle points to "F" indicating a full tank. When the tank is empty and the least current is flowing, the needle points to "E" indicating an empty tank.
The system is fail safe; a fault that opens the electrical circuit causes the indicator to show the tank as being empty (which will provoke the driver to refill the tank(in theory)) rather than full (which would allow the driver to run out of fuel with no prior notification).
Systems that measure large fuel tanks (including underground storage tanks) may use the same electro-mechanical principle or may make use of a pressure sensor, sometimes connected to a mercury manometer.
Large airplanes use a different fuel gauge design principle. An airplane has a few (around 30 on an A320) low voltage capacitors where the fuel can go between them. At different fuel levels there are different capacitances (i.e. capacitance proportional to the height of fuel) and therefore the level of fuel can be determined. For the aircraft pitch and roll attitudes the fuel computer works out how much fuel there is (slightly different on different manufacturers). In total this is more than 99% accurate.