You can't disable right-click with HTML alone. HTML has no attribute, tag, or event that blocks the context menu; that behavior comes from JavaScript. The practical version of this task is one small script plus a body tag, and it only works while JavaScript is enabled. Add oncontextmenu="return false" to the element and the browser stops opening its menu on that page. That single line is the whole "HTML" answer for most people, and it's also the version that fails most often in real use, so the sections below cover the stricter script, the common breaks, and what you can realistically expect from any of it.

What "disable right click" actually means in a browser

The right mouse button triggers the browser's contextmenu event on whatever element sits under the cursor. When nothing cancels that event, the browser draws its menu: Back, Reload, Save image as, Inspect, and so on. "Disabling right click" just means canceling that event before the menu appears.

Three things follow from that mechanism, and they set the ceiling for everything else:

The handler runs inside the page's own JavaScript sandbox. Anyone who opens developer tools and removes the attribute or re-enables the event gets the menu back. The menu isn't the only copy route. Browser menus, keyboard shortcuts, view-source, reader modes, and saved page files all bypass it entirely. The event fires per document. An iframe showing another site, or a page opened in a new tab by direct link, isn't covered by your handler.

So treat this as a speed bump for casual visitors, not a lock. That framing matters because most people who ask for this feature are really asking "how do I stop people copying my images or text," and the honest answer to that is different.

The one-line body attribute

The fastest working method is an inline attribute on the tag:

When the menu event fires on the body, the inline handler runs and return false cancels the default action. Because events bubble up, it also catches right-clicks on most elements inside the body, including images and links.

Success check: open the page in a desktop browser, right-click on the heading, a paragraph, and an image. The menu should not appear anywhere. If it appears on an image, that element likely has its own handler that runs first (more on that below). If the menu appears on a link or button, the same caveat applies: the closest handler wins, and a handler on a child element that doesn't cancel the event can let the menu through even when the body attribute is present.

This approach fails silently in one important case: if JavaScript is disabled, inline handlers don't run, and right-click works normally. It's also the method most likely to be stripped by content security policies on larger sites, which is why the script version is more portable.

The script version with a named function

The cleaner method puts the logic in a script and attaches it to the document, not the tag:

Place this in the (with the listener attached to document) or at the end of . The preventDefault() call cancels the default menu without returning anything, which keeps the handler compatible with modern event handling.

A few practical notes on this version:

Attach to document, not a single element, unless you actually want the block scoped to one region. Attaching to document covers the whole page, including elements added later. You don't need to block related events like mousedown or selectstart for this purpose; the menu is controlled by contextmenu alone. Blocking extra events causes side effects described further down. A named function helps when you need to remove the block later, for example on a page that should allow right-click only after a modal closes. Keeping a reference to the function lets you call removeEventListener with the same reference.

Success check: right-click anywhere on the page. No menu. Then open the browser console, run document.dispatchEvent(new MouseEvent('contextmenu')), and confirm nothing happens; that isolates your handler from an element-specific one.

Adding a "right-click is disabled" message

Often the request isn't just to block the menu but to tell the visitor why. You can swap the menu for an alert or an on-page banner:

An on-page note is better than alert() for two reasons: it doesn't interrupt navigation, and it doesn't fire repeatedly if the visitor right-clicks several times. If you use an alert, guard it with a flag so it appears once per page view rather than on every click.

Success check: right-click twice in a row and confirm the note appears and disappears on schedule, and that turning off the script restores the normal menu.

What breaks this, and how to test for it

The block is easy to defeat, and knowing the failure points tells you what to test:

JavaScript disabled. The page loads, the attribute and script don't run, and the menu works. Test in your browser's settings with scripting off. Long-press on mobile. Touch devices fire contextmenu on some browsers and a different long-press flow on others. iOS Safari and Android Chrome both show link previews and selection handles that the desktop handler doesn't fully suppress. Test on at least one iPhone and one Android device if mobile matters. Inside iframes. A frame pointing at another origin won't run your handler inside its document. Your block applies only to your page. DevTools and extensions. Users can delete the attribute, remove the listener, or use an extension that re-enables context menus. There's no defense against this from page code. Element-specific handlers. A framework or third-party widget that attaches its own contextmenu listener without calling preventDefault can let the menu through on that element even when the document handler exists. Inspect the element in DevTools and check for competing listeners. Saved or cached pages. A visitor who saves the page and opens the local file still gets the handler, but one who reads the source can see the script immediately. Nothing here is hidden.

The success test for all of these is the same: try the right-click on the most important element, then check the console for errors, then check whether removing your script restores the menu. If removing the script doesn't restore it, something else on the page is blocking the menu, not your code.

The accessibility and UX cost

Blocking the context menu has real downsides that are easy to miss in a quick test:

Keyboard users lose a shortcut. The context-menu key (and Shift+F10 on Windows) opens the same menu. If you're blocking for copyright reasons, blocking only the mouse leaves the keyboard route open, which is inconsistent. If you block both, you've removed a standard navigation aid for people who rely on it. Power users read it as hostility. The menu includes standard actions like Back, Reload, and copy for accessibility tools. Visitors who right-click out of habit get a dead click that looks like a broken page. It doesn't stop copying anyway. Ctrl+C, the browser's Edit menu, Reader View, and print-to-PDF all copy text. Screenshots and the browser's own "Save image as" via the page menu copy images once the page is saved. The block adds friction only for the least likely copier: someone who right-clicks before trying Ctrl+C. Search engines and crawlers ignore it. The handler is invisible to indexing and has no effect on how a page ranks.

Given that, I'd use the block only when a stakeholder specifically asks for it, keep it to the page or image gallery in question, and pair it with a visible note. Don't ship it sitewide as a default.

If the real goal is protecting images or text

The right-click question is usually a proxy for "how do I keep people from taking my content." No front-end technique does that. Images in a browser have to be downloaded to be displayed, so the file is already on the visitor's machine; the menu is just one way to save it. The visible menu is cosmetic compared with disabling the save path.

What actually helps, in rough order of effort to effectiveness:

Watermarks and provenance. Visible watermarks on images and image metadata (EXIF copyright, IPTC credit) survive casual sharing and make reuse traceable. They don't stop copying; they make attribution possible. Thumbnails plus originals behind a login. Serve reduced-size images publicly and full-size files only to authenticated users. The page still loads something, but the valuable file isn't in the public HTML. Server-side access rules. Hotlink protection, signed URLs, and per-user access logs are the layer that matters if the content is genuinely sensitive. Text: no copy controls, but clear terms. A visible copyright line and terms page is more effective than blocking Ctrl+C, because it tells honest people what's allowed.

Disabling right-click belongs in the same bucket as those measures as a deterrent, not a control. If someone copies your images despite it, the practical remedy is a takedown or license request, not more JavaScript.

A worked expectation check

Suppose the goal is to stop a casual visitor from saving a portfolio image. With the script in place, that visitor right-clicks, sees no menu, and moves on. Success: the casual case is blocked, and that's the whole benefit.

Now suppose the same visitor wants the image and knows one thing: the browser's own View menu includes "Save page as," and the page source lists the image URL. That visitor saves the page and opens the image file. The script cost them perhaps thirty seconds. You can estimate the real effect like this: if only casual visitors are the target, the block works against most of them, and it works on desktop right-clicks specifically. If determined visitors are the target, the block works against none of them, because the file is already delivered to their machine.

That's the arithmetic to present to a stakeholder who asks for the feature: it stops the casual right-click, not the copy, and it doesn't touch the save path.

Final check before you ship

Run through this list once, on a staging URL rather than your live site:

1: Right-click on text, links, images, and an embedded video. All should be blocked. 2: Turn off JavaScript in one browser and confirm the page still loads and the menu works normally (this is expected, not a bug). 3: Long-press on at least one phone. Check whether the preview or selection menus appear. 4: Open DevTools, delete the attribute or the listener, and confirm the site is back to normal. If deleting your code doesn't restore the menu, another script is in the way. 5: Check the keyboard menu key and Shift+F10 on Windows. Decide whether you're comfortable with the inconsistency if they still work. 6: Confirm the block is scoped to the pages you intend, not the whole site.

If step 4 or step 5 surprises you, that's the moment to reconsider whether the block is worth shipping at all. The feature is ordinary and low-risk to implement, but it's also a warning sign when a page's content protection depends on it. For a page with genuinely sensitive material, the right move is a qualified web developer or security review of the server-side access controls, not an HTML attribute.