The best time to travel to Morocco varies depending on what you want to see and do while you're there. The country has a diverse landscape, from the Sahara Desert to the Atlas Mountains, so the weather can vary greatly depending on where you are. Generally, the best time to visit Morocco is in spring or autumn, when the weather is more moderate. You can also visit in winter, although this is when Morocco's most popular cities, such as Marrakech and Fez, can be a bit more crowded.
If you're interested in seeing the Erg Chebbi desert, the best time to go is during the winter months, when temperatures are cooler. Spring and autumn are also good times to visit the desert.