Answer
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:
We are not allowed to hug members of the opposite sex outside of our immediate family members. Hugging your partner in and of itself does not invalidate the fast; we read in Islamic sources that the Prophet used to kiss his wives while fasting.
Responding to your question, Sheikh Ahmad Kutty, a senior lecturer and an Islamic scholar at the Islamic Institute of Toronto, Ontario, Canada, states:
I commend you for your desire to understand the rules of Islam and for your desire to observe the fast. I pray to Allah to help you remain on the straight path and safeguard your religion and honor.
May your fasting give you strength to remain ever-steadfast on the path of obedience and help you shun all vices that Allah has forbidden. If you do so, you will certainly belong to the category of people to whom the Prophet (peace be upon him) gave the following glad tidings: “A time will come when it becomes hard for a person to be steadfast on religion (because of overwhelming temptations). Thus, those who hold firmly to their religion in those times will be like those who are holding live coal!” (At-Tirmidhi). I pray to Allah to make us belong to this category of people.
Now, with regard to your question about hugging members of the opposite sex, I must say that, as Muslims, we are not allowed to hug members of the opposite sex outside of our immediate family members—the reason for this being that Allah wants to save us against weaknesses inherent in our own nature.
Such actions may or may not be lead to fornication, but since fornication is considered a grave sin and an abomination in the sight of Allah, Allah wants us to not even come close to it. He tells us, “Do not even go near fornication for it is an indecent thing and an evil way” (Al-Israa’ 17:32).
It is, therefore, out of Allah’s infinite compassion and mercy towards us that He has forbidden such acts, not only during Ramadan, but also at other times.
But if your question is about hugging your own spouse to whom you are married, then that is altogether a different issue. Hugging your partner in and of itself does not invalidate the fast; we read in Islamic sources that the Prophet (peace be upon him) used to kiss his wives while fasting.
Almighty Allah knows best.