The Great Barrier Reef as we know it today is about 8000 years old; a mere heartbeat in the aeons of geological time. This age reflects a period during which the sea level has remained more or less constant. However, we could also claim a much greater age for the GBR, for its origins go back to a time when sea-floor spreading caused Australia to separate from the great southern landmass of Gondwana.
For 160 million years we've been drifting northwards. By 25 million years ago the north-eastern continental shelf of Australia had reached the warm seas of the tropics, waters already rich in coral growth. In these shallow, sunlit seas the first coral colonies of what would become the GBR began to form. With the continuing movement northwards, more of the continental shelf was washed by warmer waters and so the reefs spread south. This is why the GBR's oldest parts are in the north and its youngest in the south.
Over the past 2 million years there have been extended periods of cooling and subsequent warming in Earth's climate; a phenomenon that continues today (we're currently living in a warm interglacial period). At the peak of the most recent ice age, around 18,000 years ago, almost a third of Earth's water was frozen in polar icecaps and consequently the sea levels on the Australian continental shelf were as much as 120 metres lower than today's. Around 10,000 years ago the polar ice began to melt and gradually flooded Earth's low-lying regions. Along Australia's north-eastern coast, segments of the mainland became isolated by these rising seas, giving birth to the so-called high, or continental, islands, such as the Lizard Island group, Hinchinbrook and the Whitsundays.
While sea levels rose and fell on the GBR during this period of climatic change, coral growth responded accordingly. As the seas rose, the reefs grew. With falling sea levels, the corals died off on exposure to the atmosphere and over time their calcium skeletons became chemically transformed into limestone. This limestone was slowly eroded by rain and wind, and formed terraces that in many cases provided the foundation for new coral growth at the next rise in sea level.
Source: McCoy, M. (1999) The Australian Geographic Book of the Great Barrier Reef. Australian Geographic: Terrey Hiils, p. 19.