You have probably experienced static
electricity. It's the charge that you create when you scuff your
feet on a rug. Then when you touch a doorknob, you get a small shock. That's
static electricity.
The reason why it works is a little more complicated. To start, you
have to know that every object is made up of billions of tiny particles,
called protons
and electrons.
These particles are so small they can only be seen with special microscopes.
Despite their small size, protons and electrons carry an electrical
charge. Protons carry a "positive" charge, while electrons carry a "negative"
energy charge.
Usually, the two different charges balance each other out, and nothing
happens. But when two objects with like charges (all positive or all negative)
come together, the charges repel and the objects move away from each other.
Objects with opposite charges attract each other because the different
charges want to enter a state of balance with each other.
Objects can get a negative charge by picking up electrons from other
objects. For example, when your shoes scuff against the rug, your shoes
are actually picking up electrons from the rug. The electrons fly over
your body, giving you a negative charge.
Your new electrons fly over your body because they are looking for a
positive charge. If you touch a metal doorknob, the electrons on your body
will leap into the metal, attracted by the protons there. The transfer
of electrons is actually a small electrical current, and produces the tiny
electric shock you feel.
Lightning is like static electricity, except on a much bigger scale.
Both lightning and static electricity happen because of the attraction
between the opposite charges.