Quicksand is made up mostly of four ingredients - sand, water, salt and clay. When subject to vibration, the mushy mixture can not support any weight thus, if the quicksand is disturbed (you step in it), the dense layers will begin packing tightly around the body part as you sink and become trapped. Your movements after that will cause you to "dig" yourself deeper into the quicksand. The more you struggle in the quicksand it will further liquefy causing you to sink more.
If you find yourself in quicksand try to remain still and breath deeply. Your body will float being it is less dense than the quicksand. The deep breathing will allow you to remain calm and more buoyant.
Immediately drop anything you are carrying with weight such as a backpack.
In order to get out of quicksand, you must make all of your movements slowly. Rapid movements will only result in getting yourself stuck deeper.
Depending on how much quicksand is surrounding you, it could take a long time to work yourself out. If you feel your muscles tiring, take small breaks keeping your lungs full of air from deep breathing and float very still. (Note: if you are in a dangerous tidal zone you may be in a race against time).
Start by making small circles with the part of your body that is trapped (your legs). This will re-introduce more water into the quicksand (between the particles) reducing the density which will make it easier to pull your legs out. Push on solid ground to lift yourself out.
You can use a walking stick or anything else flat on the surface and use it to push against to pull yourself out of the quicksand.
If you have a rope and someone with you, let them pull you out. Don't help them. By trying to pull yourself out you will actually be making it harder for them. If they are not strong enough to pull you out, have them anchor the rope to something firm that will provide solid support for the rope while you attempt to extract yourself.