There’s no doubt that since the inception of the internet, the fight against content theft has always been on the increase as content thieves are always on the rise.

how to disable right click

In this short tutorial, I’ll be guiding you through a set of ways you can easily disable right click on your website, blog or webpage using any of the methods below.

Before we continue, one thing you should bear in mind is that disabling right click can be useful in some websites and become useless for others. For instance, disabling right click on this blog ( would do more harm than good as many people won’t be able to copy various codes I’ve given out here. So use this function wisely.

Below, you’ll learn how to disable right click using JavaScript, CSS and HTML body tag

Disabling Right Click Using HTML Body Tag

After you must have designed a webpage let’s say using DreamWeaver, it is very much easy to disable right click by means of adding oncontextmenu handler in body tag of webpage.

When you view the source code of your newly designed webpage, search for <body>, add the oncontextmenu handler to it as
<body oncontextmenu=”return false;” >

 <body oncontextmenu="return false;">
Disable Right Click In HTML

Then Save. It works like charm, your content would be more secured as right click would be disabled.

Disabling Right Click Using CSS

This is another pretty easy method you can use in disabling right click. One thing I like about this method is that people barely know that CSS can disable text selection and might not be able to find ways to outsmart this method unlike the Javascript method.

As much as we know that we are not necessarily disabling right click here, we are disabling the ability to select text using the the user-select CSS property, thus on right click, you won’t see the copy option. In this method, I’m assuming that the CSS region you wish to disable right click is specified as a body  in your CSS (body). You can as well add the below CSS properties to any class name you wish. When this method is combined with any other methods, users won’t be able to either select text or right click. It’s up to you to choose if you’d combine or use this alone. Below is the CSS snippet to add to your CSS code to disable right click.

body {
-webkit-user-select: none;  /* Chrome all / Safari all */
-moz-user-select: none;     /* Firefox all */
-ms-user-select: none;      /* IE 10+ */
-o-user-select: none;
user-select: none;
Disable Select Using CSS

Add it to your site’s CSS file and save. You won’t be able to see copy whenever you right click.

Disabling Right Click Using Javascript

Using Javascript to disable right click is one of the widely used methods around the web. I actually don’t prefer this method as content thieves can easily outsmart this method by disabling Javascript on their web browsers. 

Simply add the below code to the head section of your HTML code.

document.addEventListener('contextmenu', event => event.preventDefault());
Disable Right Click With Javascript

I hope you find this guide useful. Feel free to let us know any problems you encountered using the comment box below.


  1. I have inages with the class “.mfp-img”.

    In my css fle I have written:

    .mfp-img {
    -webkit-user-select: none; /* Chrome all / Safari all */
    -moz-user-select: none; /* Firefox all */
    -ms-user-select: none; /* IE 10+ */
    -o-user-select: none;

    Yet, I can still right click and save images. See this jsfiddle:

    What am I doing wrong?


  2. You have to put it right on top of the page before <?php starts
    Example :

    document.addEventListener(‘contextmenu’, event => event.preventDefault());

  3. I have used the right on top, before starting my php script as to prevent my visitors from downloading my music from my site as I am busy developing a web based AUTO DJ script for PODCASTING schedules, rotations, adverts, jingles which works without a shoutcast server, Icecast server or any other Auto DJ software. It works on any WEBSITE. This helped me a lot. Thanks …


Please enter your comment!
Please enter your name here