During the early dynasties, spanning 788-1549, Morocco was shaped by Berber tribes and Muslim rulers. The Idrisids, who ruled from 788 to 974, used simple white flags to symbolize the purity of faith, peace, and spirituality. These banners likely contained inscriptions from the Qur'an, such as “There is no god but Allah,” emphasizing the religious legitimacy of the dynasty, which was considered to be descended from the Prophet Muhammad through Idris I. The Almoravids, who came to power in 1040, developed this tradition by using white flags with inscriptions such as “There is no god but Allah, and Muhammad is his prophet” for military units of 100 soldiers. The white color represented spiritual rigor, while individual black flags could symbolize the fight against “disbelief,” reflecting the connection to the Abbasid caliphate in Baghdad. The Almohads, who ruled from 1121 to 1269, used white flags with quotes from the Qur'an, such as “Your God is the only God” (Qur'an 2:163), emphasizing monotheism and religious reform. Some sources mention red, black, and white checkerboard flags of individual tribes or military units, but white remained the dominant color of the state. The Marinids (1244-1465) and the Vattasids (1472-1549) kept white flags with inscriptions symbolizing purity and power, which flew over Fez, the Marinid capital, and were used in battles against Christian forces in Andalusia.
The Saadin dynasty, which came to power in 1549, continued to use white flags to emphasize religious devotion and dynastic authority. Inscriptions such as “Allah desires to purify you, O people of the house” (Qur'an 33:33) reflected the connection to the Prophet Muhammad through the Sharifs, the descendants of his family. The white color symbolized peace, spiritual strength, and purity, which was important in the fight against Portuguese outposts on the coast, in particular in the Battle of Al-Qasr al-Kebir in 1578, where Morocco won. The flags remained simple, without complicated emblems, and were used both in military campaigns and for ceremonial purposes, confirming the unity of Morocco under the Saadis. These banners were flown over the new capital of Marrakech and on diplomatic missions to the Ottoman Empire.
When the Alawite dynasty came to power in 1666, the red flag became a national symbol. The color represented courage, sacrifice, and a connection to the Prophet Muhammad through the descendants of his daughter Fatima and son-in-law Ali, the fourth caliph. The color red was also associated with the sharifs of Mecca and the imams of Yemen, which gave the dynasty religious legitimacy in the eyes of Muslims. The flag was a simple red cloth without symbols, which was raised daily on the fortresses of Rabat, Salé, Tangier, and other cities, symbolizing the sultan's power. In the eighteenth and nineteenth centuries, the red color reflected pan-Arab unity and resistance to European pressure, particularly from Portugal, Spain, and France. This flag was used in diplomatic relations, for example, during negotiations with Great Britain, as well as in naval operations where Moroccan ships confronted piracy.

In 1912, Morocco came under French and Spanish protectorates, which changed the use of national symbols, although the red flag remained as a symbol of the sultanate on land. In 1915, Sultan Yusuf added a green five-pointed star, known as the Seal of Solomon, to the red cloth by decree of November 17, symbolizing wisdom and protection. During the protectorate (1912-1956), colonial restrictions were in place at sea, which led to the emergence of separate flags. The French zone used the red flag of the sultanate with the addition of a blue-white-red tricolor in the canton (upper left corner), symbolizing French power and control over foreign policy and defense. The Spanish zone used a red flag with a green field on which a white five-pointed star was placed, reflecting Spanish influence but preserving Islamic symbolism for the local population. In 1921-1926, the Republic of the Reef, led by Abd al-Kerim, operated in northern Morocco, using a red flag with a white diamond in the center, a green crescent, and a six-pointed star. The red color represented resistance to colonization, the white diamond represented purity of intent, and the crescent and star represented Islamic identity and the struggle for freedom. This flag became a symbol of the anti-colonial movement. After gaining independence on March 2, 1956, the red flag with a green five-pointed star, whose proportions are 2:3, became the official national symbol. The star occupies one-third of the flag's height and points upward, symbolizing spiritual uplift. This design embodies the courage, faith, unity and natural heritage of Morocco, remaining unchanged to this day.