In Taipei buildings swayed for up to 20 seconds when the quake hit but local television said there were no immediate reports of casualties or damage anywhere on the island.
Earthquakes frequently rattle Taiwan but most are minor and cause little or no damage.
However, a 7.6-magnitude earthquake in central Taiwan in 1999 killed more than 2,300 people.