In Islam, family is the cornerstone of the society and sex is viewed as a practical aspect of Islam's perception of the family.
Sex is an aspect of human behavior; however, in Islam, behavior of any kind is not divorced from belief.
Thus, people who believe in God, understand their individual responsibility to fulfill their God-given mission on earth, and realize that this earthly life will end with death, then resurrection and accountability, will definitely behave in a different way from someone who has none of these beliefs.
There are three aspects of human behavior: spiritual, intellectual, and physical; and, uniquely, Islam provides satisfaction for all of them.
For the spirit, Islam enjoins remembrance and worship of God. For the intellect, there is God's invitation to all human beings to ponder on and understand the universe and the natural laws governing it and humankind.
And for the physical aspect, there is the permission to satisfy the need for food, sex, and other material things. In Islam, the satisfaction of sexual needs are not contradictory to the spiritual nature of human beings.
Islam permits human beings to satisfy all these three types of legitimate needs, the only qualification being that they should be satisfied according to the commands laid down by God: They should be satisfied in a wholesome and pure manner, without excess.
[The love of desires, of women and sons and hoarded treasures of gold and silver and well-bred horses and cattle and tilth, is made to seem fair to men; this is the provision of the life of this world; and Allah is He with Whom is the good goal (of life).] ( Aal `Imran 3:14)
The Qur'an does not condemn humans for having this love of desires, but it just reminds them that such are the possessions of this world's life and nearness to God is the best of goals.
Thus, the Qur'an asks humans to strike a balance between legitimate pursuit of material gain and the pursuit of the rewards of the hereafter. God forbids the immoral and excessive pursuit of material pleasures, particularly when it is done by using unlawful methods.
It is possible to identify two extremes pertaining to sexual morals which have appeared throughout history.
The first is the view that sex is unclean and contrary to goodness, spirituality, and faith in God; in other words, something to be suppressed and resisted. This view resulted in the institution of monasticism, celibacy, and in the belief that marriage and sex were inevitable evils, rather than blessings from God.
The second more predominant view is that which allows the pursuit of sexual and other pleasures regardless of moral considerations and the harmful effects on both individuals and society at large. It is known that the former view led to psychological problems and the association of sex with demonic powers whereas the latter led to widespread adultery, fornication, preoccupation with sex, and the development of sex as a business.
Both of these extremes go against human nature, which requires that certain desires are fulfilled in moderation within the moral framework that religious teachings provide and at the same time protects the individual and the family from the dangerous consequences of unhampered pursuit of sexual satisfaction.
It has been noted by many observers that many harms result from an over preoccupation with sex. There is harm to the health, the moral character, and the person's ability to be patient.
When someone satisfies this sexual desire regardless of necessity, their moral character is destroyed because their indulgence leads to selfishness, opportunism, lack of responsibility and care for family, lying, deception, internal conflicts in the conscience of the individual, drug addiction, theft, rape, and even murder. And it is not just the individual who suffers; society as a whole and the family in particular suffer from the degradation of the human being in this way.
Islam teaches that people should be brought up in such a way that their heart contains sincere God-consciousness (taqwa) in order to be able to persevere in the face of any temptation created by powerful sexual promptings.
Together with this faith, people should additionally be made aware of the teachings of Islam and know right from wrong; thus they will never be confused between vice and virtue and will realize that Islam prohibits the satisfaction of the sexual urge outside the bounds of marriage. Islam prohibits not only pre- and extramarital sexual relationships, but also all types of perversions like homosexuality.
Prophet Muhammad's life is a clear example that marriage and sex are permissible in Islam and are acts that Allah rewards Muslims for, providing their actions fall within the boundaries of Islam. Also Prophet Muhammad instructed that those who do not have the means to marry and wish to preserve their chastity should practice fasting as a means to help them control their desires.