Spring (March–May) is the best time to visit most of Morocco. Temperatures are mild across the country, wildflowers cover the Atlas and the south, and the heat of summer hasn't arrived yet. This is peak season in Fez and Marrakech, so expect crowds in the medinas — but the weather makes it worth it.
Autumn (September–November) is the second-best window. The summer crowds thin out, temperatures drop to pleasant levels, and the light in the desert and the mountains is beautiful. October is excellent almost everywhere.
Summer (June–August) is genuinely brutal in the interior. Marrakech and the south regularly hit 40°C or above. The coast — Essaouira, Agadir, Tangier — stays bearable thanks to Atlantic breezes. Essaouira in particular is reliably windy and cool and makes a sensible summer escape. The High Atlas and the Rif are also manageable in summer, and the Gnaoua Festival in Essaouira (June) is worth planning around.
Winter (December–February) is mild on the coasts and cold in the mountains. Skiing is possible at Oukaïmeden (70km south of Marrakech) and Mischliffen in the Middle Atlas from January to March. The desert is actually pleasant in winter — days are warm and clear, nights are cold. The pre-Saharan zones around Merzouga and Zagora are best visited outside of the scorching summer months.
Ramadan moves through the calendar year by year (it follows the lunar calendar, shifting about 11 days earlier each year). Travel during Ramadan is entirely possible — and offers a unique window into Moroccan life — but opening hours are restricted, many restaurants close during the day, and the pace of life changes significantly. Iftar (the sunset breaking of the fast) is a wonderful communal event to witness.