
A hub dynamo is a small generator built into a bicycle wheel. As the wheel turns, magnets pass a set of coils. The changing magnetic field makes a voltage in the coils. A wire carries the power up to the light.
Why does the light stay on at a stop?
Some lights have a small capacitor or a battery. It stores some energy while the bicycle is moving. After the wheel stops, that stored energy can keep the lamp on for a while.
Does the light make the bicycle harder to pedal?
The rider supplies the energy for the light. Making electricity adds some drag. The amount depends on the generator and electrical load, and for a small lamp it can be hard to notice.
For more on how movement and magnetic fields make electricity, see Basics of Electric Utilities 101.