We extend the mathematical theory of rigidity of frameworks (graphs embedded in $d$-dimensional space) to consider nonlocal rigidity and flexibility properties. We provide conditions on a framework under which (I) as the framework flexes continuously it must remain inside a small ball, a property we call almost-rigidity; (II) any other framework with the same edge lengths must lie outside a much larger ball; (III) if the framework deforms by some given amount, its edge lengths change by a minimum amount; (IV) there is a nearby framework that is prestress stable, and thus rigid. The conditions can be tested efficiently using semidefinite programming. The test is a slight extension of the test for prestress stability of a framework, and gives analytic expressions for the radii of the balls and the edge length changes. Examples illustrate how the theory may be applied in practice, and we provide an algorithm to test for rigidity or almost-rigidity. We briefly discuss how the theory may be applied to tensegrities.