They happen due to slip on a [fault plane.](https://en.wikipedia.org/wiki/Fault_(geology)) There are faults throughout the tectonic plates but they are concentrated at or near plate boundaries. Intraplate earthquakes can occur very far from plate boundaries, (usually as a result of built up stress reactivating an old fault that exists from when that area used to be associated with a plate boundary in the geologic past), though they are definitely not as common or as large in magnitude.
All of the above is thinking of earthquakes due to tectonic forces, ie. due to stress building up because tectonic plates move around, but there are also earthquakes that can occur due to magma moving through the crust. Magma can (and does) fracture it’s own paths through the Earth’s crust, this sort of thing is monitored in volcanically active regions to help give an indication of when eruptions might be imminent. The sorts of earthquakes that get generated by magma movement are distinguishable from the purely tectonic ones, they tend to occur as a bunch of similar magnitude events close together known as earthquake swarms.
Latest Answers