How to disable href in an a element with CSS?

Spread the love

Sometimes, we want to disable href in an a element with CSS.

In this article, we’ll look at how to disable href in an a element with CSS.

How to disable href in an a element with CSS?

To disable href in an a element with CSS, we set its pointer-events CSS property.

For instance, we write

<a href="link.html" class="disabled">Link</a>

to add an a element.

Then we write

a.disabled {
  pointer-events: none;
  cursor: default;
}

to disable pointer events on the link with pointer-events: none;.

Disabling pointer events will stop us from being able to go to the URL the link is linked to.

Conclusion

To disable href in an a element with CSS, we set its pointer-events CSS property.

Leave a Reply

Your email address will not be published.