Not an expert, but from my limited knowledge: 'sex' pertains to the shape of your junk/what sex cells your body generates (i.e. eggs/sperm) and 'gender' is generally a cultural construct pertaining to maleness and femaleness.
So, gender can relate to biological 'sex', but can also relate to...