Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable a link using only CSS

Tags:

html

css

Is there a way to disable a link using CSS?

I have a class called current-page and want links with this class to be disabled so that no action occurs when they are clicked.

like image 314
RSK Avatar asked Jan 19 '10 04:01

RSK


People also ask

How do I make a link not clickable CSS?

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 disable a URL link?

It is still possible to disable a link by following 3 steps: remove the href attribute so that it can no longer receive the focus. add a role="link" so that it is always considered a link by screen readers. add an attribute aria-disabled="true" so that it is indicated as being disabled.

How do you disable an element in CSS?

To disable a HTML anchor element with CSS, we can apply the pointer-events: none style. pointer-events: none will disable all click events on the anchor element. This is a great option when you only have access to class or style attributes. It can even be used to disable all the HTML links on a page.

How do I unlink HTML and CSS?

All you have to do is delete the code at the top of the HTML! Once you do, the page automatically unlinks from the stylesheet.


1 Answers

From this solution:

[aria-current="page"] {   pointer-events: none;   cursor: default;   text-decoration: none;   color: black; }
<a href="link.html" aria-current="page">Link</a>

For browser support, please see https://caniuse.com/#feat=pointer-events. If you need to support Internet Explorer, there is a workaround; see this answer.

Warning: The use of pointer-events in CSS for non-SVG elements is experimental. The feature used to be part of the CSS 3 UI draft specification but, due to many open issues, has been postponed to CSS 4.

like image 161
15 revs, 14 users 24% Avatar answered Sep 19 '22 06:09

15 revs, 14 users 24%