An earthquake is a very sudden, violent ground shaking that begins with absolutely no warning.
An earthquake may last for half a minute, but in that short time buildings may begin to sway and then collapse.
An earthquake is produced in areas where the Earth's rocks are pushing against one another. The earthquake occurs when the rocks snap. The snap happens in one place and then often travels for many miles, something like a zipper being undone. Then it stops.
When the ground snaps, it is like a hammer striking a bell. The Earth shakes like a bell with a certain rhythm. That rhythm can move through the Earth for thousands of miles, although the surface only shakes for a few tens of miles around the zone where the rocks broke.
Because the ground shakes like a bell, buildings pick up the shake, just like striking a tuning fork. If the rhythm of the ground shaking matches the natural rhythm of a building, then the building will shake very violently and may fall down. The same is true for bridges, elevated roads and other structures.
Earthquakes snap power lines, water supplies and other essential utilities. Roads and railways are usually damaged. That makes getting rescue equipment into an earthquake zone very difficult.
Only some parts of the Earth's surface are pushing together in a way that makes them liable to snap. Earthquakes occur in lines around the world. Other places suffer very few earthquakes.