The exact cause of eyelid spasm or twitching is unknown. But it is very common.
The spasms or twitching usually involve either the upper or lower eyelid of just one eye. The symptom may last for several minutes, even a couple hours. But it usually resolves on its own and might not happen again for many months or years.
People tend to get eyelid spasms or twitching when they feel stressed or tired. There is no specific treatment when the twitching does occur. Relaxation breathing or other relaxation techniques might help. The twitching always stops when you fall asleep.
There is a more troublesome form of muscle spasms of the eyelids around the eye called blepharospasm. These are more persistent muscle spasms that can be very uncomfortable. The eye itself is not affected. In addition to the discomfort, the spasms can be severe enough to keep the eyelids closed.
You should see your doctor if you have persistent spasms or twitching.