Invention
Richard Trevithick built the first steam locomotive, which was first used in February of 1804. The refinements necessary for a practically useful steam engine took some time, but the technology quickly became an important part of commerce around the world.
How it Works
Most steam locomotives had a coal furnace that could generate an extreme amount of heat. This heat was used to rapidly heat water, and the resulting steam generated enough pressure to force a rod attached to the locomotive's wheel forward with some force. This spent steam was then allowed out of the engine as exhaust, and newly generated would push the rod again.
Replacement
Locomotives with modern diesel engines gradually replaced steam locomotives. Today, steam locomotives are only used in a few specific circumstances. Some railroads continue to use the old steam locomotives because tourists and train enthusiasts favor them. Steam locomotives are also used at high altitudes because diesel engines are hampered by the lower air pressure.