Formal occasions are where local codes are strictest and most rewarding to get right, and the safe universal is a dark suit for men and an elegant, modestly cut dress or suit for women; that combination passes at business meetings and most formal events worldwide. From that baseline, adjust by occasion and country.
Weddings vary the most. In many cultures guests dress vibrantly, and in South Asian weddings colourful attire is expected, with foreign guests often warmly encouraged to wear local dress, which hosts genuinely appreciate rather than see as costume. Colour taboos matter: white is reserved for the bride in Western weddings, while white or black can be mourning colours at some Asian events, and red may be reserved for brides in some traditions, so ask your hosts what is appropriate, which is itself a respected question. Religious ceremonies add modesty layers: covered shoulders and knees, head coverings in some traditions, and shoes off where customary.
Business formality tracks the sector and country, with banking, law, and government running conservative nearly everywhere and first meetings deserving your formal best. Funerals call for subdued colours, usually black or dark tones, though some cultures use white, another thing to confirm locally. When invitations are unclear, asking the host directly is standard practice everywhere and always better than guessing wrong.