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

Issue

For example if I have this:

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

Is there anything I can use for the style attribute that will make it so the link isn’t clickable and won’t take me to page.html?

Or, is my only option to simply not wrap ‘page link’ in an anchor tag?

Edit: I want to state why I want to do this so that people may be able to provide better advice. I am trying to set up my application so that the developer can choose what type of navigation style they want.

So, I have a list of links and one is always currently selected and all the others aren’t. For the links that are not selected, I obviously want those to be normal clickable anchor tags. But for the selected link, some people prefer that the link remains clickable while others like to make it not clickable.

Now I could easily just programmatically not wrap an anchor tags around the selected link. But I figure it will be more elegant if I can always wrap the selected link in something like:

<a id="current" href="link.html">link</a>

and then let the developer control the linking style through CSS.

Solution

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.

Answered By – Diego Unanue

Answer Checked By – Marie Seifert (AngularFixing Admin)

Leave a Reply

Your email address will not be published.