There are three main types of coral reefs: fringing reefs, barrier reefs, and atolls. Fringing reefs are the most common; they grow seaward directly from the shore and form borders along coastlines and around islands. Barrier reefs also follow a shoreline, but farther out, separated from the land by a lagoon of open, often deep water.
An atoll forms when a fringing reef grows around a volcanic island that then sinks completely below sea level while the coral keeps growing upward. Atolls are usually circular or oval with a central lagoon, and parts of the reef may rise above the water as small islands. All three types are built by hard, or stony, corals; soft corals live on reefs but do not build them.
Source: NOAA National Ocean Service: How Do Coral Reefs Form?
Image: Bora Bora and its barrier reef from the International Space Station, NASA Johnson Space Center, public domain, via Wikimedia Commons.
Related answers