Sling Academy
Home/Tailwind CSS/How to Disable a Link with Tailwind CSS

How to Disable a Link with Tailwind CSS

Last updated: December 09, 2023

When developing web frontends with Tailwind CSS, there might be situations where you may need to disable a link. One common reason is that you want to prevent the user from clicking on a link that is not yet functional or relevant. For example, if you have a link to a page that is under construction, you may want to disable it until the page is ready.

Tailwind CSS brings to the table a utility class named pointer-events-none, which makes an element ignore pointer events, such as clicking or hovering. This can be useful for disabling a link that you don’t want the user to interact with. Optionally, you can also add other classes to change the appearance of the link, such as opacity-50 to make it semi-transparent, or cursor-not-allowed to show a different cursor when the user moves the mouse over the link.

Example:

<body>
    <div class="container mx-auto p-8">
        <h1 class="text-4xl font-bold mb-4">Tailwind CSS Disable Link Example</h1>
        <p class="text-xl mt-4 mb-2">This is a disabled link:</p>
        <a href="https://api.slingacademy.com"
            class="text-blue-500 hover:text-blue-700 underline pointer-events-none opacity-50 cursor-not-allowed">Example Link</a>

        <p class="text-xl mt-4 mb-2">This is a normal link:</p>
        <a href="https://www.slingacademy.com" class="text-blue-500 hover:text-blue-700 underline">Example Link</a>
    </div>
</body>

Result:

That’s it. Happy coding & make beautiful things with Tailwind CSS. Goodbye. See you in the next tutorial.

Next Article: How to Change Mouse Cursor in Tailwind CSS

Previous Article: How to Style the HR Element with Tailwind CSS

Series: Basic Tailwind CSS Tutorials for Beginners

Tailwind CSS

Related Articles

You May Also Like

  • How to Create Striped Tables with Tailwind CSS
  • Tailwind CSS: Creating Shimmer Loading Placeholder (Skeleton)
  • Tailwind CSS: How to Create Parallax Scrolling Effect
  • How to Style Lists in Tailwind CSS
  • Text Underline in Tailwind CSS
  • How to Change Mouse Cursor in Tailwind CSS
  • Form Validation with Tailwind CSS (without Javascript)
  • first-of-type and last-of-type in Tailwind CSS
  • Tailwind CSS: Create a User Card with Circle Avatar
  • Tailwind CSS: How to Create Columns with the Same Height
  • How to Style Placeholder Text with Tailwind CSS
  • Tailwind CSS: Make a Div 100% Height & Width of the Viewport
  • Using :not() selector in Tailwind CSS
  • Tailwind CSS: How to Create a Stepper
  • Using ::before and ::after in Tailwind CSS
  • Tailwind CSS: How to Create a Vertical Divider Line
  • How to Create Pill Buttons with Tailwind CSS
  • Tailwind CSS: How to Disable Text Selection
  • Tailwind CSS: How to Disable Resizing of Textarea