Reef-building corals were confined to relatively shallow depths because many of these corals have microscopic algae called zooxanthellae living inside their soft tissues.
These algae are often important for the corals’ nutrition and growth, but require sunlight for photosynthesis. There is no sunlight deep in the water.