Is it possible to make an HTML anchor tag not clickable/linkable using CSS?
Make an <a>
tag unclickable with CSS by using this snippet:
And apply the class directly:
pointer-events: none;
takes the clickability off the link, and cursor: default;
replaces the iconic hand cursor with a standard arrow, further stressing the deactivated state of the link.
Exploring link style alteration
Fine-tuning the look
With functionality sorted, you can also turn off the visual alarms of hyperlinks:
This brings the <a>
elements in line with regular text.
Overlay strategy: a tale of layers
Using an element to cover the link with greater z-index
is another JavaScript-independent solution:
The link still shows, but is actually concealed by an invisible div on top, hence, it's unclickable.
Usability: keeping user confusions at bay
Keep in mind, users might be puzzled when a seemingly clickable link is inactive. You need to remedy this by clear visual hints.
Code for dynamic content & advanced cases
Keeping non-clickable consistent
In single-page applications or AJAX-loaded content, the content changes. Therefore, non-clickable styles need to be implemented consistently using the same class, such as .no-click
, across the entire application.
Beyond CSS: JavaScript
While this post is CSS-focused, you're reminded that JavaScript or jQuery provide finer control, like allowing link clicks conditionally:
However, this stab at JavaScript introduces additional complexity and a need for it, which isn't perfect for simpler use-cases.
Mind the accessibility
Keep an eye on accessibility—make sure screen readers or keyboard navigation handle the link-turned-text properly. You might have to remove or edit the href
attribute or add tabindex="-1"
to avoid focus.
Refinements for better UX
Let the user know
Provide the user some clarity if there are non-clickable elements on the page, maybe through a tooltip or color opacity:
Responsive adaptation
Assess how your non-clickable links behave across devices and screen sizes:
Media queries can alter the behavior for touch devices without hover features. For them, pointer-events
could be set to auto
.
Transition magic
Add transition effects for that polished look:
Such transitions convey the non-active status of a link seamlessly without an abrupt flip.
Was this article helpful?