Morocco is relaxed compared to some neighbors, but it's still a majority-Muslim country where modest dress earns real, practical benefits: fewer stares, fewer aggressive sales pitches, and an easier time in mosques' outer courtyards and rural villages.
General guideline for both men and women: shoulders and knees covered in cities and villages away from resort pools or beach zones. A lightweight scarf is genuinely useful — for sun, dust, covering up on the spot when needed, and covering hair if you step into certain religious sites. Beachwear is fine at beach resorts and pool areas, but change before walking through town.
This isn't about strict rules — it's simply about comfort and being treated as a respectful guest rather than an obvious tourist target.