We have seen quicksand in enough movies to have a general idea about how it works: you struggle, you sink, right? At least until you ultimately grab the usual branch to plug yourself out of the trap.
Quicksand, in fact, is basically solid ground -either sand or any similar grainy soil- oversaturated in water. This usually happens when damp soil is agitated due, for example, to an earthquake. If the water in the soil can’t escape, the whole thing liquifies and the surface can not support weight anymore. Water and vibration reduce friction between solid particles and the combined material starts to behave like a viscous liquid. Another usual explanation is an underground water flow fighting gravity on the surface.
Typically, quicksand is easier to find in humid places like riverbanks, beaches or marches. Indeed, the phenomenon can be appreciated in small scale when one is standing on the sea shore.
In any case, drowning in quicksand is actually quite difficult. First, deposits are not that deep, just a few feet tops. Second, quicksand density approximately doubles water density, meaning that it is actually easier to float in quicksand than in water, in the same way that it is easier to float in salty water than in sweet water.
Actually, the problem comes when quicksand is very dense, since moving out of there would be like trying to get out of a concrete pit. In this case, movies are correct: the more you struggle, the deeper you go. The key idea would be to move out through slow movements -to reduce friction- and to spread -to increase the body surface area to float easier-. In brief, to try to swim slowly out of the pit.
More information on How Stuff Works