Map from Google - Morocco

Morocco has a Mediterranean climate on the coasts, while it's desert in the inland areas, and continental in the highest mountains.

The Atlantic coast enjoys a mild climate, similar to that of the Mediterranean, and even milder. Winters look rather like spring or autumn, with long sunny periods, and summers are pleasantly warm and sunny.
The rains are not abundant, however, from November to March can sometimes be concentrated in a few hours, filling the ancient river beds (called wadis) and causing flooding.
A cool current flows into the sea, therefore it remains cool even in summer; furthermore, due to this current, along the coast, especially in Essaouira and the bay of Agadir, fogs and mists can form on summer mornings. Strange as it may seem, the sea is even a bit colder in the southern part of the coast (see Essaouira, Agadir), compared with the northern part, from Tangier to Casablanca.
In Agadir, the average temperature in January is 14 °C (57 °F), while that of July, August and September is 22 °C (72 °F). Throughout the year, a hot wind from the interior can blow for a few days, bringing warm temperatures in winter, around 30 °C (86 °F), and uncomfortably hot days in summer, with peaks above 40 °C (104 °F).
Here are the average temperatures of Agadir.
Average temperatures - Agadir
AgadirJanFebMarAprMayJunJulAugSepOctNovDec
AgadirJFMAMJJASOND
Min (°C)891112141618181715129
Max (°C)202022212324262626252320
Min (°F)464852545761646463595448
Max (°F)686872707375797979777368

In the southern part of the coast, the rainfall is scarce, not reaching 250 millimetres (10 inches) per year, and occurs almost all from late autumn to early spring. Here is the average precipitation in Agadir.
Average precipitation - Agadir
AgadirJanFebMarAprMayJunJulAugSepOctNovDecYear
AgadirJFMAMJJASONDY
Prec. (mm)5030251651016203040224
Prec.(in)21.210.60.20000.20.81.21.68.8
Days54532101134635

The sea temperature remains cool even in summer, and reaches a maximum of 21 °C (70 °F) in August and September.
Sea temperature - Agadir
AgadirJanFebMarAprMayJunJulAugSepOctNovDec
AgadirJFMAMJJASOND
Sea (°C)171717171819202121201918
Sea (°F)636363636466687070686664

Further to the north along the coast, Essaouira is particularly cool and windy during the summer months, and also foggy in the morning.
Average temperatures - Essaouira
EssaouiraJanFebMarAprMayJunJulAugSepOctNovDec
EssaouiraJFMAMJJASOND
Min (°C)101112131416171817161411
Max (°C)181819192021232323222119
Min (°F)505254555761636463615752
Max (°F)646466666870737373727066

In Casablanca, a little more to the north, the average temperature goes from 13 °C (55.5 °F) in January, to 23 °C (73 °F) in July and August. Even here, heatwaves are possible, but they are less intense than in Agadir. The rains, a little more abundant, about 400 mm (16 in) per year, are concentrated in the period from November to April.
Average temperatures - Casablanca
CasablancaJanFebMarAprMayJunJulAugSepOctNovDec
CasablancaJFMAMJJASOND
Min (°C)9911121517192019151210
Max (°C)171819202224262626242018
Min (°F)484852545963666866595450
Max (°F)636466687275797979756864

As mentioned, in the central part of the coast, the temperature of the sea is a bit higher than in the southern part, and becomes acceptable for swimming in August and September.
Sea temperature - Casablanca
CasablancaJanFebMarAprMayJunJulAugSepOctNovDec
CasablancaJFMAMJJASOND
Sea (°C)171717181921222323222019
Sea (°F)636363646670727373726866

In Rabat, the capital, the climate is similar to that of Casablanca.
In Tangier, further north, the winter is similar to that of Casablanca, but the summer is warmer: normally the maximum touches 28 °C (82 °F) instead of 25/26 °C (77/79 °F). It may seem strange that the summer is warmer in the north than in the south, but the fact is that the effects of the cold current here are weaker.
Average temperatures - Tangier
TangierJanFebMarAprMayJunJulAugSepOctNovDec
TangierJFMAMJJASOND
Min (°C)8910111316181918151210
Max (°C)161617182124282827221917
Min (°F)464850525561646664595450
Max (°F)616163647075828281726663

In this northern part of the coast, rainfall is relatively abundant, as the weather disturbances pass frequently in autumn and winter. Here the average rainfall in Tangier.
Average precipitation - Tangier
TangierJanFebMarAprMayJunJulAugSepOctNovDecYear
TangierJFMAMJJASONDY
Prec. (mm)10510070603515231565135130735
Prec.(in)4.13.92.82.41.40.60.10.10.62.65.35.128.9
Days10111010530139101284

The sea temperature in this northern part of the coast is similar to that of Casablanca and Rabat.
Sea temperature - Tangier
TangierJanFebMarAprMayJunJulAugSepOctNovDec
TangierJFMAMJJASOND
Sea (°C)161616161820222322201917
Sea (°F)616161616468727372686663

On the Mediterranean coast, the climate is typically Mediterranean, with mild and moderately rainy winters, which resemble those of the Atlantic coast, and hot, sunny summers, warmer than on the Atlantic coast: in Al Hoceima the temperature ranges from 12 °C (53.5 °F) in January to 25 °C (77 °F) in August. In the Spanish enclave of Melilla, the climate is similar. Even here there are sudden increases in temperature when the wind blows from the desert, a situation more common in spring. Infiltration from the Atlantic Ocean makes the sea a little colder than in other Mediterranean countries, and similar to that of Tangier, so that even here the water temperature reaches 23 °C (73 °F) in August.

Marrakesh

Moving towards the interior, the effect of the cold Atlantic current is sharply reduced, so the imperial cities have a climate characterized by hot summers, while winters are slightly colder, partly because of the higher altitude.
In particular, in Marrakesh, 450 metres (1,450 ft) above sea level, the average goes from 12 °C (53.5 °F) in January, to 28 °C (82 °F) in July and August. The sun shines all year round, and the rains are concentrated from mid-October to April, though usually not abundant; in summer, long sunny periods are interrupted by sporadic thunderstorms. In the worst moments, the temperature can exceed 45 °C (113 °F).
Average temperatures - Marrakesh
MarrakeshJanFebMarAprMayJunJulAugSepOctNovDec
MarrakeshJFMAMJJASOND
Min (°C)68911141620201815107
Max (°C)182022242731363632272219
Min (°F)434648525761686864595045
Max (°F)646872758188979790817266

Further north, Fez, 400 metres (1,300 feet) above sea level, is a bit colder and rainier: the average goes from 9 °C (48 °F) in January to 26 °C (79 °F) in July and August; the annual precipitation is about 500 mm (20 in). The climate is similar in Meknes, 500 metres (1,600 feet) above sea level, and a short distance from Fez.

In mountainous areas, the chains of Atlas and Rif have a colder climate due to the altitude, so that there are even ski resorts (see Ifrane). Summers are hot during the day, while nights are more or less cool, depending on altitude.
The eastern slopes of the Atlas, towards Algeria, have an arid climate; in winter the temperature is cold at night, while in summer the heat is intense, but tempered by the altitude, at least compared with the Algerian desert. In Er Rachidia, at 1,000 metres (3,300 feet) above sea level, the average daily temperature in July is 30 °C (86 °F).

When to go

To visit the imperial cities of Morocco you can choose spring and autumn, in March-April and from October to mid-November. Both cold nights and hot days cannot be excluded, but generally the temperature is pleasant, and the sky is almost always clear, with rare rains.
For a beach holiday, along the Atlantic coast you can go from July to September, and along the Mediterranean coast in July and August. As mentioned, the Atlantic waters are cool even in summer, and fogs and mists may form in the morning along the coast, reducing the hours of sunshine.

What to pack

In winter: on both the Atlantic and Mediterranean coast, spring/autumn clothes, jacket and sweater, raincoat or umbrella; for the imperial cities you can add a warm hat for the evening; for the mountain areas, warm clothes, down jacket, gloves; for the desert, light clothing, but also sweater, warm jacket for the evening, scarf for the wind-borne sand and dust.

In summer: on the Mediterranean coast, light clothing, a light sweatshirt for the evening; on the Atlantic coast, especially in Agadir and Essaouira, better to add a pair of jeans, a sweatshirt, a light jacket and a scarf. For inland and desert areas, loose fitting, light-coloured clothing, light and long shirt and pants, sun hat and desert turban; sunglasses (even graduated instead of contact lenses), a sweatshirt for the evening; sleeping bag to sleep outdoors; hiking shoes or sandals. In the mountains, sweater and jacket for overnight stays outdoors. For women, it is best to avoid shorts and miniskirts, especially in rural and non-tourist areas.