How to Disable Clicks on a Link or Button

Quick Summary

  • Give the link a disabled class styled with pointer-events: none, which stops mouse and touch clicks without any JavaScript.
  • The pointer-events property doesn't affect the keyboard, so add aria-disabled and tabindex -1 when the link must be fully inactive.
  • For a real button element, use its disabled attribute instead, since it blocks both clicks and keyboard use.

Sometimes a link has to stay visible but stop working, for example a step that isn’t available yet. The CSS pointer-events property can disable a link click, from a mouse or a touch, with no JavaScript needed.

The block holds two parts: the link markup for your HTML, and the rule for your stylesheet. The // labels only separate them and aren’t valid CSS comments, so copy just the a.disabled rule into your CSS file.

CSS
//html code
<a href="link.html" class="disabled">Link</a>


//css code
a.disabled {
   pointer-events: none;
   cursor: default;
}

How it works

  • pointer-events: none makes the link ignore mouse and touch events, so clicking it does nothing and its hover styles don’t apply.
  • cursor: default asks for the normal arrow instead of the pointing hand. With pointer-events: none the browser shows the cursor of whatever is under the link, so in practice this line rarely changes anything.
  • Add or remove the disabled class, for example with JavaScript, to turn the link off and on. Disabling the WooCommerce quantity minus button shows the same on/off idea for a real button, using jQuery and its disabled attribute.

Keyboard users can still reach the link with the Tab key and open it with Enter, because pointer-events doesn’t affect the keyboard. Add aria-disabled="true" and tabindex="-1" to the link if it must be fully inactive. For a real <button>, use its disabled attribute instead, which blocks both clicks and keyboard use; the selector here only targets a elements.

Share on X (opens in a new tab) Share on LinkedIn (opens in a new tab) Share on Facebook (opens in a new tab)

ChatGPT (opens in a new tab) Claude (opens in a new tab) Gemini (opens in a new tab) Perplexity (opens in a new tab) Grok (opens in a new tab)

More Insights

See More