How to disable a link using only CSS
To disable a link using CSS, apply the pointer-events
property with value none
. Modify style properties to visually demonstrate that the link is non-functional:
Include the class in your HTML:
Adding tabindex="-1"
ensures navigation skips the link, but, be aware, an astute user can still decipher the href using browser tools.
Mastering the specifics
CSS hover effects
To visibly communicate your disabled link to users, augment your CSS:
Accessibility for everyone
Implementing aria-current="page"
informs screen readers about navigation current state. However, accessibility in CSS is pretty stubborn and refuses to disable functionalities.
Age ain't nothing but a number
Older browsers might be grumpy and refuse to follow pointer-events
. Be prepared to provide alternative methods or coffee for piqued users.
Let bootstrap kick in
Are you a Bootstrap user? Try the .disabled
class which visually blends disabled links with existing framework styles:
Pro-tips: Going beyond basic disables
All-round deactivation
Despite pointer-events: none
making a link visually non-interactive, certain users could still access it. To ensure absolute deactivation, consider removing the href
attribute or utilizing JavaScript — a hefty decision indeed!
Semantics aren't just for linguists
Semantically-strong documents thrive on well-defined roles like role="button"
. But don't mix roles with states. Even though they're peas in a pod, they don't always agree.
User experience
A CSS-disabled link could be, well, confusing, especially due to lack of typical user-interactive responses. Understand your audience and adapt your design patterns accordingly.
True deactivation
To fully disable a link, including from keyboard users, you may need to triage the situation. The CSS scalpel cuts incisively but not always deeply enough.
Was this article helpful?