The underlying root cause of earthquakes is the phenomenon of plate tectonics. The surface later of the Earth is made up of many large plates of soil and rock that slide over the underlying layer. At the boundaries where these plates meet, there are so-called faults: breaks in the earth's crust where the blocks of rock on each side are moving in different directions. Earthquakes are most common along fault lines. The most famous fault is the San Andreas fault in California which marks the plate boundary between the Pacific oceanic plate and the North American continental plate. It is more than 650 miles long.
There are many different kinds of faults, but all of them involve different plates of rock pushing tightly together and creating friction as they move. If the friction becomes high enough, the two plates are locked, unable to slide against each other. But the forces in the plates continue to push, increasing the pressure until it overcomes the force of the friction. When that happens, the blocks will suddenly snap forward. And this sudden release of pent-up force creates an earthquake.
The reason most earthquakes occur around plate boundaries is because this is where the strain from plate movements are most intense, creating groups of inter-connected faults, so that an earthquake in one can trigger subsequent quakes in others. This is also why several earthquakes can occur in a short period of time.
If you get caught in an earthquake, remember to Drop, Cover and Hold On. Drop under a sturdy desk or table and hold on for stability. Protect your eyes by pressing your face against your arm. If there is no nearby piece of furniture, sit on the floor against an interior wall, away from windows, bookcases, or any tall furniture that could fall on you. Don't stand in the doorway -- the middle of the room is safer.