Most earthquakes occur along the boundaries between the Earth's tectonic plates. The crust of the Earth is divided into plates. When a plate collides with or slides past another plate, this causes earthquakes. For example, as the Pacific plate moves past the North American plate, many earthquakes occur along the coast of California.
Earthquakes can also occur in the middle of a plate if there is a fault. As the plates move, they are subject to a great deal of stress, and this causes weak points to develop away from the edge of the plate. Over time, enough stress can accumulate and cause an earthquake along such a fault.