Chefchaouen is a city of northwestern Morocco set in a saddle of the Rif at the foot of the twin peaks (Jebel Megou and Jebel Tisouka) that gave the town its name in the local Jbala speech: ash-shawen, "the horns." The town sits at the boundary between the Tarifit-speaking Rif to the east and the Jebli-Arabic-speaking Jbala upland to the west.
The town was founded in 1471 by the Idrisid sharif Moulay Ali ben Rashid as a refuge for Andalusi Muslims and Jews fleeing the Castilian Reconquista, particularly after the fall of Granada in 1492 and the subsequent Morisco expulsions of the early seventeenth century. The medina retains a strong Andalusi architectural and culinary signature: tiled fountains, internal courtyards, gabled tile roofs unusual elsewhere in Morocco, and a cuisine in which Andalusi and Jbala traditions are difficult to separate.
The blue-painted walls and alleys that have made Chefchaouen internationally familiar since the 2010s are a more recent feature, conventionally dated to the early-to-mid twentieth century and variously attributed to the small surviving Jewish community of the city or to a rebuilding programme of the Spanish Protectorate period (1912–1956). The contemporary tourism economy organised around the blue medina has substantially transformed the town's daily life.
The Spanish Protectorate administration governed Chefchaouen alongside the Rif as the Northern Zone of Morocco, with the city taken from Rifian forces in 1920 and held — except for the period of the Republic of the Rif (1924–1926) — until Moroccan independence in 1956. The Andalusi-Berber synthesis of the Jbala upland survives in the contemporary craft economy and in the surrounding rural communes.