Link

A styled anchor component for navigation with built-in icon support

Import

import { Link } from '@heroui/react';

Usage

"use client";

import {Link} from "@heroui/react";

export function LinkBasic() {
  return (
    <div className="flex flex-col gap-3">
      <Link href="#">Simple link</Link>

      <Link href="https://heroui.com" rel="noopener noreferrer" target="_blank">
        External link to HeroUI
        <Link.Icon />
      </Link>

      <Link isDisabled href="#">
        Disabled link
      </Link>
    </div>
  );
}

With Icons

"use client";

import {Link} from "@heroui/react";
import {Icon} from "@iconify/react";

export function LinkWithIcon() {
  return (
    <div className="flex flex-col gap-3">
      <Link href="#">
        Default with icon
        <Link.Icon />
      </Link>

      <Link className="gap-1" href="#">
        Custom icon
        <Link.Icon>
          <Icon className="size-4" icon="gravity-ui:arrow-up-right-from-square" />
        </Link.Icon>
      </Link>

      <Link className="gap-1" href="#">
        <Link.Icon>
          <Icon className="size-4" icon="gravity-ui:house" />
        </Link.Icon>
        Home
      </Link>
    </div>
  );
}

Styling

Passing Tailwind CSS classes

import {Link} from '@heroui/react';

function CustomLink() {
  return (
    <Link
      href="#"
      className="text-lg font-bold text-accent hover:text-accent/80"
    >
      Custom styled link
    </Link>
  );
}

Customizing the component classes

To customize the Link component classes, you can use the @layer components directive.
Learn more.

@layer components {
  .link {
    @apply font-semibold no-underline hover:underline;
  }
}

HeroUI follows the BEM methodology to ensure component variants and states are reusable and easy to customize.

CSS Classes

The Link component uses these CSS classes (View source styles):

Base Classes

  • .link - Base link styles with underline on hover

Interactive States

The component supports both CSS pseudo-classes and data attributes for flexibility:

  • Focus: :focus-visible or [data-focus-visible="true"]
  • Disabled: :disabled or [aria-disabled="true"]

API Reference

PropTypeDefaultDescription
hrefstring-URL for navigation
targetstring-Specifies where to open the linked document
relstring-Specifies the relationship between documents
isDisabledbooleanfalseDisables link interaction
showIconbooleanfalseShows the link icon
iconPlacement"start" | "end""end"Position of the icon
classNamestring-Additional CSS classes
childrenReact.ReactNode-Link content
onPress(e: PressEvent) => void-Handler called when the link is pressed
autoFocusboolean-Whether the element should receive focus on render

Link.Icon Props

PropTypeDefaultDescription
asChildbooleanfalseMerge props with child element
childrenReact.ReactNode-Custom icon element
classNamestring-Additional CSS classes