Marrakesh was founded in 1070 or 1071 CE by Yusuf ibn Tashfin, founder of the Almoravid dynasty, becoming the capital of an empire that stretched from the Sahara in the south to Al-Andalus in the north. The name "Marrakesh" itself — from which "Morocco" derives in many European languages — is believed to come from Amazigh words meaning "Land of God." From these intertwined Amazigh-Arab-Andalusian roots grew a city that later became the capital of several successive dynasties: the Almoravids, then the Almohads, who built the famous Koutoubia Mosque in the 12th century as a symbol of their religious and political authority, then the Saadians in the 16th century, who left a dazzling architectural legacy, most notably their royal tombs, rediscovered only in 1917 after being deliberately hidden for centuries to prevent desecration.

The city is nicknamed the "Red City" for the color of its walls and many of its old buildings — an earthy, sandy hue derived from the local clay traditionally used in construction — and this color has effectively become municipal law, requiring new buildings in the old city and surrounding areas to preserve the unified visual character. Marrakesh's cultural identity was shaped through a deep blending of Amazigh people (North Africa's indigenous population), Arabs who arrived with the Islamic conquests, Andalusians who brought the arts and architecture of Islamic Spain, and also Saharan influences carried by trade caravans that made Marrakesh a key stop on the trans-Saharan gold, salt, and slave trade routes for centuries.

One of the most vivid expressions of this cultural blend is Gnaoua music, a spiritual musical tradition with roots in sub-Saharan Africa, brought by traders and formerly enslaved people, which fuses African rhythms with Sufi Islamic ritual and remains strongly present in Jemaa el-Fnaa and at a dedicated annual festival in nearby Essaouira. Marrakesh's old city was designated a UNESCO World Heritage Site in 1985, in recognition of its rare density of historic landmarks within a living urban fabric still used daily rather than functioning as a mere open-air museum.

In the modern era, Marrakesh gained a new cultural layer when Western artists and designers discovered it in the 20th century, chief among them French designer Yves Saint Laurent, who fell so deeply in love with the city and its colors that he chose it as his final resting place, his ashes scattered in the Majorelle Garden he rescued from ruin. Today, Marrakesh combines its deep historical identity with vitality as a contemporary artistic and cultural hub, making it one of the most complex and culturally rich cities in all of North Africa.