It was founded in 833 by the Idrisid dynasty, under the reign of the Emir Muhammad ibn Idris II. It was originally the summer capital of the Idrisid dynasty from the 8th to 10th centuries after they were driven out of Fes by the Fatimids.
Established in 833 by the Idrisid dynasty, it functioned as a summer capital for the Idrisids during their rule from the 8th to the 10th centuries. The Idrisids were displaced from Fes by the Fatimids.