This is a block of glass with a triangular cross section.
Light waves are refracted as they enter the glass because they are slowed down.
The spectrum is produced because different colours of light travel at different speeds in glass.
Red light is slowed down least by glass and is refracted least.
Violet light is slowed down most by glass and is refracted most.
As a result, the coloured light spreads out to form a spectrum of white light.
This is called dispersion.
There is an easy way to remember the order of the colours of white light by using a sentence: Richard Of York Gave Battle In Vain
Red, Orange, Yellow, Green, Blue, Indigo, Violet.