The reason for the diffraction effect was explained
by the Dutch physicist and mathematician Christian Huygens
in 1678. He showed that any wave can be thought of as
spreading spherically at every point along its wavefront.
All these little spherical 'wavelets' are constantly
interacting, so can maintain a planar (or flat) wavefront.
But if this wavefront is interrupted by an obstacle
the wave spreads spherically at the points where it
has been broken.
Diffraction
gratings work by splitting a planar wavefront at many
regular points. The wavelets which pass through the
gaps in the grating will spread spherically and interfere
with each other. When several wavelets are in phase
with each other they will add together and produce a
strong signal in a detector, and if they are out of
phase they will cancel out and produce a very weak signal.
Diffraction patterns made with light will show successive
bright and dark areas demonstrating the differences
in phase between several wavelets.