You can wear shorts at the beach and on the resort's property. It is also acceptable to wear bikinis and swimwear at the beach.
In other places, it is better to dress more conservatively. Shorts should preferably be loose-fitting, three-quarter pants that end below the knee. Ladies should avoid wearing very short shorts in public.
Walking around shirtless is not culturally acceptable, even for blokes. For women, wearing mini-skirts and skimpy outfits is sure to cause offence. Be particularly mindful when visiting Stone Town and mosques, where your torso and shoulders need to be covered too.