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.
//html code
<a href="link.html" class="disabled">Link</a>
//css code
a.disabled {
pointer-events: none;
cursor: default;
}How it works
pointer-events: nonemakes the link ignore mouse and touch events, so clicking it does nothing and its hover styles don’t apply.cursor: defaultasks for the normal arrow instead of the pointing hand. Withpointer-events: nonethe browser shows the cursor of whatever is under the link, so in practice this line rarely changes anything.- Add or remove the
disabledclass, 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 itsdisabledattribute.
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.
Related articles
- styling hover and focus states as a pair: why keyboard users need visible focus styles too
- cancelling a link’s default jump with preventDefault: the JavaScript way to stop a link from acting normally
