When two galaxies are close enough, their gravitational attraction draws them to each other. That attraction increases as the galaxies move closer. The Milky Way and Andromeda are examples of two galaxies that will probably eventually collide (no sooner than 5 billion years in the future).
In a direct encounter between two massive spiral galaxies such as these, huge cold clouds of molecules (gas) will be compressed, and millions of new stars will burst into life like a string of lights. As the galaxies first swing by each other, their once orderly disks will become jumbled with dust, gas, and brilliant blue star clusters. Then the galaxies may do a slow, graceful U-turn and plunge into each other. This second encounter will trigger another burst of star formation, which will drive the remaining gas and dust from the combined system. As the stars settle into randomly oriented orbits, the resulting system may take on an elliptical appearance.
HubbleSite and STScI are not responsible for content found outside of hubblesite.org and stsci.edu