Sway bar allows both wheels to cycle in unison, like going over a speed bump.
But it resists individual cycling of the wheels, like going around a sweeping corner or a bump that only one wheel goes over.
The bar itself is more like a spring, with a spring rate to allow a certain degree of individual wheel cycle, but not to much.
It attaches to the frame which is fixed, and to each side of the axle (rear) or each control arm (front). Deflection from the fixed position on the frame is controlled by the rating or strength of the bar, often but not always related to its thickness.
So good for on road stability, not so good for off road articulation. Life is full of choices.