The electrons present in atoms of elements absorb energy and move to excited states and when they return back to ground state with emission of energy in visible spectrum. So the colours observed during fire works is the emitted energy by various elements in different fire works.