A Track Stand is a technique riders can use to stay balanced on their bicycles by holding their weight equally on both feet and while moving only minimal distances. Track stands are very useful for stopping in traffic and quickly moving again. It is especially useful if you have clips on your pedals as it is sometimes tricky to get your feet back in the clips.
In order to to a track stand, you must hold the cranks in horizontal position with your dominant foot set forward. If you are doing this on a fixie, than you can do it anywhere because you have the ability to create backwards motion. Bikers with freewheels must do it on an uphill surface so they can create backwards motion. The handlebars should be held at a 45 degree angle and that will convert the bike’s forward and back motion into a side to side motion. This is what keeps the bike directly below your center of gravity.
Just practice and you’ll get the hang of it.