The attraction from a fixed strength magnet decreases with increased distance, and increases at closer distances. This is unstable. For a stable system, the opposite is needed, variations from a stable position should push it back to the target position.
Stable magnetic levitation can be achieved by measuring the position and speed of the object being levitated, and using a feedback loop which continuously adjusts one or more electromagnets to correct the object's motion, thus forming a servomechanism.
Many systems use magnetic attraction pulling upwards against gravity for these kinds of systems as this gives some inherent lateral stability, but some use a combination of magnetic attraction and magnetic repulsion to push upwards.
Either system represents examples of ElectroMagnetic Suspension (EMS). For a very simple example, some tabletop levitation demonstrations use this principle, and the object cuts a beam of light to measure the position of the object. The electromagnet is above the object being levitated; the electromagnet is turned off whenever the object gets too close, and turned back on when it falls further away. Such a simple system is not very robust; far more effective control systems exist, but this illustrates the basic idea.
EMS magnetic levitation trains are based on this kind of levitation: The train wraps around the track, and is pulled upwards from below. The servo controls keep it safely at a constant distance from the track