{"id":6688,"date":"2018-09-02T04:57:48","date_gmt":"2018-09-02T08:57:48","guid":{"rendered":"http:\/\/local.brightwhiz\/?p=6688"},"modified":"2021-12-08T11:32:00","modified_gmt":"2021-12-08T16:32:00","slug":"disable-a-link-using-only-css-html","status":"publish","type":"post","link":"http:\/\/local.brightwhiz\/disable-a-link-using-only-css-html\/","title":{"rendered":"How to Disable a Link Using Only CSS and HTML"},"content":{"rendered":"\n

So the real question is why would you want to disable a link? Wouldn’t it just make sense to have a none link text in its place?<\/p>\n\n\n\n

Well, that could happen but as with anything web development, it is not that simple. You might want to disable a link based on certain conditions be it dynamic or served straight from the server in a disabled state.<\/p>\n\n\n\n

Whatever the case, the good news is that it is not complicated in the least of terms.<\/p>\n\n\n\n

CSS<\/a> allows us one of the simplest ways to get this done. It is lightweight, safe, and works with all major browsers whether JavaScript<\/a> is turned on or off.<\/p>\n\n\n\n

You Could, of Course, Disable a Link by Simulating<\/h2>\n\n\n\n

You can simulate a disabled link by simply hiding the real URL with no link text then style it appropriately. From the example below, you can see how this can be achieved.<\/p>\n\n\n\n

<div class="disableable">\n <a class="toggleLink" href="example.php">Some Text<\/a>\n <span class="toggleLink">Some Text<\/span\n<\/div><\/code><\/pre>\n\n\n\n

Your CSS can be as follows.<\/p>\n\n\n\n

.disableable a.toggleLink { display: inline; }\n.disableable span.toggleLink { display: none; }<\/code><\/pre>\n\n\n\n

Now all you need to do is track the even that will flip the span and the A to be either adopt the inline or none display properties.<\/p>\n\n\n\n

Using the Pure CSS and HTML Solution<\/h2>\n\n\n\n

Here we can simplify matters even more. Taking from the previous example we can have a single line of HTML<\/a> like so.<\/p>\n\n\n\n

<a class="disabled" href="javascript:void(0)">Some Text<\/a><\/code><\/pre>\n\n\n\n

We then use the class “disabled” and the “href” can be set to do nothing using the JavaScript void function call.<\/p>\n\n\n\n

In your CSS you can style the URL anchor to make it look visually disabled. This is how you can do it.<\/p>\n\n\n\n

.disabled {\n pointer-events: none;\n cursor: default; \/*optional*\/\n opacity: 0.6;\n }<\/code><\/pre>\n\n\n\n

With CSS you can disable all cursor events by setting pointer-events to none. The cursor can be set to default as a formality but since we are ignoring pointer-events including change of cursor this can be optional.<\/p>\n\n\n\n

Finally, we give it a lowered opacity (gray) to give the user a visual cue that the link has been disabled.<\/p>\n\n\n\n

There you have it. Any time you need to disable a URL you can simply add the “disabled” class to the URL tag.<\/p>\n","protected":false},"excerpt":{"rendered":"

So the real question is why would you want to disable a link? Wouldn’t it just make sense to have a none link text in its place? Well, that could…<\/p>\n","protected":false},"author":1,"featured_media":6689,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,23,27,16],"tags":[170,303,635,637,638,643],"yoast_head":"\nDisable a Link Using Only CSS and HTML, Easier Than You Think<\/title>\n<meta name=\"description\" content=\"CSS can be used to disable a link in the simplest way possible. It is light weight, intuitive and works accross all major web browsers and platforms\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/local.brightwhiz\/disable-a-link-using-only-css-html\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Disable a Link Using Only CSS and HTML, Easier Than You Think\" \/>\n<meta property=\"og:description\" content=\"CSS can be used to disable a link in the simplest way possible. It is light weight, intuitive and works accross all major web browsers and platforms\" \/>\n<meta property=\"og:url\" content=\"http:\/\/local.brightwhiz\/disable-a-link-using-only-css-html\/\" \/>\n<meta property=\"og:site_name\" content=\"Brightwhiz.com\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/brightwhiz\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-09-02T08:57:48+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-12-08T16:32:00+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/local.brightwhiz\/wp-content\/uploads\/2018\/09\/css-disable-links.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"630\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Michael Bright\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@brightwhizmag\" \/>\n<meta name=\"twitter:site\" content=\"@brightwhizmag\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Michael Bright\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"http:\/\/local.brightwhiz\/disable-a-link-using-only-css-html\/#article\",\"isPartOf\":{\"@id\":\"http:\/\/local.brightwhiz\/disable-a-link-using-only-css-html\/\"},\"author\":{\"name\":\"Michael Bright\",\"@id\":\"http:\/\/local.brightwhiz\/#\/schema\/person\/81f0f3126f13834ae2e7f381b3028e32\"},\"headline\":\"How to Disable a Link Using Only CSS and HTML\",\"datePublished\":\"2018-09-02T08:57:48+00:00\",\"dateModified\":\"2021-12-08T16:32:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"http:\/\/local.brightwhiz\/disable-a-link-using-only-css-html\/\"},\"wordCount\":351,\"publisher\":{\"@id\":\"http:\/\/local.brightwhiz\/#organization\"},\"image\":{\"@id\":\"http:\/\/local.brightwhiz\/disable-a-link-using-only-css-html\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/local.brightwhiz\/wp-content\/uploads\/2018\/09\/css-disable-links.jpg\",\"keywords\":[\"CSS\",\"HTML\",\"Web\",\"Web Design\",\"Web Development\",\"Websites\"],\"articleSection\":[\"Articles\",\"Guides\",\"Programming\",\"Technology\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"http:\/\/local.brightwhiz\/disable-a-link-using-only-css-html\/\",\"url\":\"http:\/\/local.brightwhiz\/disable-a-link-using-only-css-html\/\",\"name\":\"Disable a Link Using Only CSS and HTML, Easier Than You Think\",\"isPartOf\":{\"@id\":\"http:\/\/local.brightwhiz\/#website\"},\"primaryImageOfPage\":{\"@id\":\"http:\/\/local.brightwhiz\/disable-a-link-using-only-css-html\/#primaryimage\"},\"image\":{\"@id\":\"http:\/\/local.brightwhiz\/disable-a-link-using-only-css-html\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/local.brightwhiz\/wp-content\/uploads\/2018\/09\/css-disable-links.jpg\",\"datePublished\":\"2018-09-02T08:57:48+00:00\",\"dateModified\":\"2021-12-08T16:32:00+00:00\",\"description\":\"CSS can be used to disable a link in the simplest way possible. It is light weight, intuitive and works accross all major web browsers and platforms\",\"breadcrumb\":{\"@id\":\"http:\/\/local.brightwhiz\/disable-a-link-using-only-css-html\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/local.brightwhiz\/disable-a-link-using-only-css-html\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/local.brightwhiz\/disable-a-link-using-only-css-html\/#primaryimage\",\"url\":\"http:\/\/local.brightwhiz\/wp-content\/uploads\/2018\/09\/css-disable-links.jpg\",\"contentUrl\":\"http:\/\/local.brightwhiz\/wp-content\/uploads\/2018\/09\/css-disable-links.jpg\",\"width\":1200,\"height\":630,\"caption\":\"Disable a Link With CSS\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/local.brightwhiz\/disable-a-link-using-only-css-html\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/local.brightwhiz\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Disable a Link Using Only CSS and HTML\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/local.brightwhiz\/#website\",\"url\":\"http:\/\/local.brightwhiz\/\",\"name\":\"Brightwhiz.com\",\"description\":\"Best Tech guides, Tutorials, and News\",\"publisher\":{\"@id\":\"http:\/\/local.brightwhiz\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/local.brightwhiz\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"http:\/\/local.brightwhiz\/#organization\",\"name\":\"Brightwhiz\",\"url\":\"http:\/\/local.brightwhiz\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/local.brightwhiz\/#\/schema\/logo\/image\/\",\"url\":\"http:\/\/local.brightwhiz\/wp-content\/uploads\/2021\/11\/brightwhiz-com-logo-orange.png\",\"contentUrl\":\"http:\/\/local.brightwhiz\/wp-content\/uploads\/2021\/11\/brightwhiz-com-logo-orange.png\",\"width\":706,\"height\":135,\"caption\":\"Brightwhiz\"},\"image\":{\"@id\":\"http:\/\/local.brightwhiz\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/brightwhiz\/\",\"https:\/\/twitter.com\/brightwhizmag\",\"https:\/\/instagram.com\/bright_whiz\/\",\"https:\/\/www.pinterest.com\/sobbayi\/\",\"https:\/\/www.youtube.com\/channel\/UC6sCdP_d_RiTIM7ErFT-PSQ\"]},{\"@type\":\"Person\",\"@id\":\"http:\/\/local.brightwhiz\/#\/schema\/person\/81f0f3126f13834ae2e7f381b3028e32\",\"name\":\"Michael Bright\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/local.brightwhiz\/#\/schema\/person\/image\/\",\"url\":\"http:\/\/1.gravatar.com\/avatar\/da90485875ff0aafa38fdd494abe87d1?s=96&d=mm&r=g\",\"contentUrl\":\"http:\/\/1.gravatar.com\/avatar\/da90485875ff0aafa38fdd494abe87d1?s=96&d=mm&r=g\",\"caption\":\"Michael Bright\"},\"sameAs\":[\"https:\/\/sobbayi.com\"],\"url\":\"http:\/\/local.brightwhiz\/author\/sobbayiadmin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Disable a Link Using Only CSS and HTML, Easier Than You Think","description":"CSS can be used to disable a link in the simplest way possible. It is light weight, intuitive and works accross all major web browsers and platforms","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/local.brightwhiz\/disable-a-link-using-only-css-html\/","og_locale":"en_US","og_type":"article","og_title":"Disable a Link Using Only CSS and HTML, Easier Than You Think","og_description":"CSS can be used to disable a link in the simplest way possible. It is light weight, intuitive and works accross all major web browsers and platforms","og_url":"http:\/\/local.brightwhiz\/disable-a-link-using-only-css-html\/","og_site_name":"Brightwhiz.com","article_publisher":"https:\/\/www.facebook.com\/brightwhiz\/","article_published_time":"2018-09-02T08:57:48+00:00","article_modified_time":"2021-12-08T16:32:00+00:00","og_image":[{"width":1200,"height":630,"url":"http:\/\/local.brightwhiz\/wp-content\/uploads\/2018\/09\/css-disable-links.jpg","type":"image\/jpeg"}],"author":"Michael Bright","twitter_card":"summary_large_image","twitter_creator":"@brightwhizmag","twitter_site":"@brightwhizmag","twitter_misc":{"Written by":"Michael Bright","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"http:\/\/local.brightwhiz\/disable-a-link-using-only-css-html\/#article","isPartOf":{"@id":"http:\/\/local.brightwhiz\/disable-a-link-using-only-css-html\/"},"author":{"name":"Michael Bright","@id":"http:\/\/local.brightwhiz\/#\/schema\/person\/81f0f3126f13834ae2e7f381b3028e32"},"headline":"How to Disable a Link Using Only CSS and HTML","datePublished":"2018-09-02T08:57:48+00:00","dateModified":"2021-12-08T16:32:00+00:00","mainEntityOfPage":{"@id":"http:\/\/local.brightwhiz\/disable-a-link-using-only-css-html\/"},"wordCount":351,"publisher":{"@id":"http:\/\/local.brightwhiz\/#organization"},"image":{"@id":"http:\/\/local.brightwhiz\/disable-a-link-using-only-css-html\/#primaryimage"},"thumbnailUrl":"http:\/\/local.brightwhiz\/wp-content\/uploads\/2018\/09\/css-disable-links.jpg","keywords":["CSS","HTML","Web","Web Design","Web Development","Websites"],"articleSection":["Articles","Guides","Programming","Technology"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"http:\/\/local.brightwhiz\/disable-a-link-using-only-css-html\/","url":"http:\/\/local.brightwhiz\/disable-a-link-using-only-css-html\/","name":"Disable a Link Using Only CSS and HTML, Easier Than You Think","isPartOf":{"@id":"http:\/\/local.brightwhiz\/#website"},"primaryImageOfPage":{"@id":"http:\/\/local.brightwhiz\/disable-a-link-using-only-css-html\/#primaryimage"},"image":{"@id":"http:\/\/local.brightwhiz\/disable-a-link-using-only-css-html\/#primaryimage"},"thumbnailUrl":"http:\/\/local.brightwhiz\/wp-content\/uploads\/2018\/09\/css-disable-links.jpg","datePublished":"2018-09-02T08:57:48+00:00","dateModified":"2021-12-08T16:32:00+00:00","description":"CSS can be used to disable a link in the simplest way possible. It is light weight, intuitive and works accross all major web browsers and platforms","breadcrumb":{"@id":"http:\/\/local.brightwhiz\/disable-a-link-using-only-css-html\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/local.brightwhiz\/disable-a-link-using-only-css-html\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/local.brightwhiz\/disable-a-link-using-only-css-html\/#primaryimage","url":"http:\/\/local.brightwhiz\/wp-content\/uploads\/2018\/09\/css-disable-links.jpg","contentUrl":"http:\/\/local.brightwhiz\/wp-content\/uploads\/2018\/09\/css-disable-links.jpg","width":1200,"height":630,"caption":"Disable a Link With CSS"},{"@type":"BreadcrumbList","@id":"http:\/\/local.brightwhiz\/disable-a-link-using-only-css-html\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/local.brightwhiz\/"},{"@type":"ListItem","position":2,"name":"How to Disable a Link Using Only CSS and HTML"}]},{"@type":"WebSite","@id":"http:\/\/local.brightwhiz\/#website","url":"http:\/\/local.brightwhiz\/","name":"Brightwhiz.com","description":"Best Tech guides, Tutorials, and News","publisher":{"@id":"http:\/\/local.brightwhiz\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/local.brightwhiz\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"http:\/\/local.brightwhiz\/#organization","name":"Brightwhiz","url":"http:\/\/local.brightwhiz\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/local.brightwhiz\/#\/schema\/logo\/image\/","url":"http:\/\/local.brightwhiz\/wp-content\/uploads\/2021\/11\/brightwhiz-com-logo-orange.png","contentUrl":"http:\/\/local.brightwhiz\/wp-content\/uploads\/2021\/11\/brightwhiz-com-logo-orange.png","width":706,"height":135,"caption":"Brightwhiz"},"image":{"@id":"http:\/\/local.brightwhiz\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/brightwhiz\/","https:\/\/twitter.com\/brightwhizmag","https:\/\/instagram.com\/bright_whiz\/","https:\/\/www.pinterest.com\/sobbayi\/","https:\/\/www.youtube.com\/channel\/UC6sCdP_d_RiTIM7ErFT-PSQ"]},{"@type":"Person","@id":"http:\/\/local.brightwhiz\/#\/schema\/person\/81f0f3126f13834ae2e7f381b3028e32","name":"Michael Bright","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/local.brightwhiz\/#\/schema\/person\/image\/","url":"http:\/\/1.gravatar.com\/avatar\/da90485875ff0aafa38fdd494abe87d1?s=96&d=mm&r=g","contentUrl":"http:\/\/1.gravatar.com\/avatar\/da90485875ff0aafa38fdd494abe87d1?s=96&d=mm&r=g","caption":"Michael Bright"},"sameAs":["https:\/\/sobbayi.com"],"url":"http:\/\/local.brightwhiz\/author\/sobbayiadmin\/"}]}},"_links":{"self":[{"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/posts\/6688"}],"collection":[{"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/comments?post=6688"}],"version-history":[{"count":0,"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/posts\/6688\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/media\/6689"}],"wp:attachment":[{"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/media?parent=6688"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/categories?post=6688"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/tags?post=6688"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}