All perfect praise be to Allah, The Lord of the Worlds. I testify that there is none worthy of worship except Allah, and that Muhammad is His slave and Messenger.
We ask Allah, the Great and Almighty, to safeguard the honor and good repute of Muslims, and to help them be obedient and God-fearing in private and in public.
It is our duty, as Muslims, to get benefit from the Internet and to crave after every beneficial science and research, especially as we find on the Internet different fields of knowledge. The Prophet said: “Cling to what is beneficial for you.” [Muslim]
Thus, the Internet is a double-edged weapon; beneficial and harmful. It is prohibited to peruse pornographic and rakish sites, since such act is forbidden. One has to void such sites, showing full obedience to Allah's Order; Allah Says (what means): {Those who follow the Messenger, the unlettered prophet, whom they find written in what they have of the Torah and the Gospel, who enjoins upon them what is right and forbids them what is wrong and makes lawful for them the good things and prohibits for them the evil…} [Quran 7:157]
Allah Also Says (what means): {Tell the believing men to reduce [some] of their vision and guard their private parts. That is purer for them. Indeed, Allah is Acquainted with what they do.} [Quran 24:30]
For sure, one who peruses such obscene sites (pictures, essays, chats…); he/she will be driven to what is worse, the worst: fornication, adultery, buggery or even to refrain from marriage. Such an action may also lead the married one to neglect his/her spouse, and then to deviation, disinclination or acute divorce.
Thereupon, you have to abandon such a sinful deed at once and repent. This action, without a doubt, brings down and deserves Allah's wrath as well as spoils and hardens the heart and smothers its light. To be helped for sincere repentance, one has to avoid such libertine sites and messages with pornography, to put off computer and then to leave out the room or to busy oneself with any other useful work. Another way is to browse Internet only in the presence of some good company.
Here, it is a natural result to masturbate due to looking at such bad sites that thrill emotions and excite lusts. Thus, it is forbidden to look at such sites and to commit the sin of masturbation.
Allah Says (what means): {And they who guard their private parts Except from their wives or those their right hands possess, for indeed, they will not be blamed - But whoever seeks beyond that, then those are the transgressors -} [Quran 23:5-7]
Such acts, i.e. to peruse lewd sites and masturbate, are forbidden, whether one is married or not. But, it is worse with respect to the married.
Finally, Muslims are to fear Allah, The Great and Almighty, and to observe His orders. They have also to know that Allah knows what they do in private and in public.
We ask Allah to reform the Muslims and their progeny and to protect them from lapse.
For more benefit on the prohibition of masturbation, please refer to Fataawa 179859, 376036, 87952, and 81167.
Allah knows best.