Cap rocks are relatively impermeable rocks layers that seal the top of reservoirs and other geologic formations. Cap rocks are commonly referred to in the context of topping oil and gas reservoirs but can also top formations of softer or less resistant rock and salt domes. Cap rocks are often formed from shale, anhydrite, or salt as discussed below.
Cap rocks form the top of reservoirs and create a layer that is impervious to fluid flow (Figure 1). By preventing fluids from flowing through it, the fluids are prevented from escaping the reservoir.
This particularly applies to oil and gas reservoirs. Oil and gas reservoirs often form in "traps". There are a few types of traps: anticlinal, fault, stratigraphic, and reef and/or salt traps. In all cases, the cap rock overlies the reservoir rock(s) (where the hydrocarbons are held), sealing the top of the trap and often the sides. Source rocks (where the hydrocarbons form) are usually at lower depths than the cap rock but not necessarily directly below it.
When a rock that is harder to break down (resists weathering) overlies an easier to break down rock (less resistant to weathering), the rock on top is referred to as cap rock. The cap rock, in this case, can protect the lower more delicate layers from weathering and erosion. Alternatively, the cap rock can remain while the more delicate lower layers are weather and eroded from under it. Both cases result in unique natural features. Buttes, mesas, scarps all form in this fashion but the most distinctive feature that forms this way are the hoodoos (Figure 2). 
Salt domes are large masses of underground salt with a small amount of anhydrite (Figure 3). Salt usually has a lower density than the surrounding rock and will attempt to flow upwards when it can. This often results in salt domes forming plug or bulge shapes as it tries to fit through weak spots in the overlying rock layer. As the salt forces its way upwards and begins to dissolve, a cap rock forms on top of the dome. Anhydrite is an evaporite mineral that is not as easily dissolved as salt. It reacts with bacteria and other substances in the ground to change into sulphur, dolomite, limestone, and/or gypsum, all of which build up to make the cap rock.