Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to make an HTML anchor tag not clickable/linkable using CSS?

Tags:

html

css

anchor

People also ask

How do you make an anchor tag not clickable in HTML?

In order to disable a HTML Anchor Link (HyperLink), the value of its HREF attribute is copied to the REL attribute and the value of HREF attribute is set to an empty JavaScript function. This makes the HTML Anchor Link (HyperLink) disabled i.e. non-clickable.

How do I remove a HyperLink in CSS?

Answer: Use the CSS pointer-events Property You can simply use the CSS pointer-events property to disable a link. The none value of this property specify the element is never the target of pointer events.

Can we use anchor tag in CSS?

CSS Code. When styling the text of the link itself, we simply reference the anchor tag class name only, and we change change things such as the text's color and other attributes. When referencing the special attributes of the anchor tag, such as link, visited, hover, and active.


You can use this css:

.inactiveLink {
   pointer-events: none;
   cursor: default;
}

And then assign the class to your html code:

<a style="" href="page.html" class="inactiveLink">page link</a>

It makes the link not clickeable and the cursor style an arrow, not a hand as the links have.

or use this style in the html:

<a style="pointer-events: none; cursor: default;" href="page.html">page link</a>

but I suggest the first approach.


That isn't too easy to do with CSS, as it's not a behavioral language (ie JavaScript), the only easy way would be to use a JavaScript OnClick Event on your anchor and to return it as false, this is probably the shortest code you could use for that:

<a href="page.html" onclick="return false">page link</a>

Yes.. It is possible using css

<a class="disable-me" href="page.html">page link</a>

.disable-me {
    pointer-events: none;
}

Or purely HTML and CSS with no events:

<div style="z-index: 1; position: absolute;">
    <a style="visibility: hidden;">Page link</a>
</div>
<a href="page.html">Page link</a>

CSS was designed to affect presentation, not behaviour.

You could use some JavaScript.

document.links[0].onclick = function(event) {
   event.preventDefault();
};