In the Name of Allah, Most Gracious, Most Merciful.
All praise and thanks are due to Allah, and peace and blessings be upon His Messenger.
In this fatwa:
Hugging your wife while fasting is permissible but you should avoid it as it may lead to further actions which nullify the fast, such as sexual intercourse.
In responding to your question, Sheikh Ahmad Kutty, a senior lecturer and an Islamic scholar at the Islamic Institute of Toronto, Ontario, Canada, states:
If you are speaking about hugging your wife while fasting, it is permissible but you should avoid it.
Aishah, the beloved wife of the Prophet (peace be upon him) was asked whether one is allowed to kiss his wife while fasting? She said, ‘no,’ then when someone pointed out to her, ‘Didn’t the Prophet kiss you while he was fasting?’, She replied, “Who among you can restrain himself as the Prophet was able to?” (Ibn Hibban)
In other words, we should avoid such actions to save ourselves from breaking our fast.
I do not see any difference between hugging and kissing; it is likely to arouse desire, and therefore should be avoided unless someone knows that he can control himself.
As for hugging the members of the opposite sex — who are not related to you in blood or marriage–, one ought to avoid it in all circumstances.
Almighty Allah knows best.