O rings are used to block a path that may otherwise allow a liquid or a gas to escape. The o ring is placed into a groove to secure them in place and then compressed between two surfaces. By squeezing the o ring, there is no more clearance for it to move and it blocks the pathway of the liquid or gas you are trying to seal in place.
When the system comes under pressure, the o ring is squeezed against the opposite wall of the groove, maintaining a perfect seal even under very high or low pressures. The materials that o rings are made from (elastomers) are naturally springy and have a desire to return to their original shape, so when the pressure ceases, they spring back to their original position, maintaining a seal and readiness for the next cycle.
In a nutshell and to answer the question of what are o rings used for, they are used to seal in a liquid or gas and are the most effective way of ensuring a robust, reliable seal.