Microscopically speaking, intermolecular forces in a spring always act to return the molecules to their equilibrium spacing. This is why (outward) external forces must be applied at both ends of a spring in order to keep the spring stretched. When the stretched spring tries to return to its un-stretched length, they end up exerting (inward) spring forces Fspring at both ends of the spring.
Usually, Fspring increases as the spring becomes more stretched. If Fspring is proportional to the extension x, the spring is said to obey Hooke’s Law. In equation form, we have
where k is the constant of proportionality called the spring constant (aka force constant).
Hooke’s Law is an example of an empirical law. It is not a fundamental law of nature. So some springs, under certain conditions, will not obey Hooke’s Law. Thankfully, most springs under most conditions do obey Hooke’s Law. Thankfully because law-abiding springs are a lot easier to analyze.
Besides springs, wires (from which springs are made of), strings, ropes, rods, rubber bands, elastic cords etc exert tensional forces when stretched. All of them, under certain conditions, and to varying extent, may obey Hooke’s Law.