Link

Links allow users to click their way from page to page. This component is styled to resemble a hyperlink and semantically renders an <a>


Installation

npx nextui-cli@latest add link
The above command is for individual installation only. You may skip this step if @nextui-org/react is already installed globally.

Import

Usage

Disabled

Sizes

Colors

Underline

External

If you pass the isExternal prop, the link will have the target="_blank" and rel="noopener noreferrer" attributes.

Custom Anchor Icon

If you pass the isBlock prop, the link will be rendered as a block element with a hover effect.

Polymorphic Component

NextUI components expose a as prop that allows you to customize the React element type that is used to render the component.

Routing

The <Link> component works with frameworks and client side routers like Next.js and React Router. See the Routing guide to learn how to set this up.

import {Link} from "@nextui-org/react";
function App() { return (
<>
<Link href="/home">Home</Link>
<Link href="/about">About</Link>
</>
);
}
return (
<>
<Link href="/home">Home</Link>
<Link href="/about">About</Link>
</>
);
}

Custom Implementation

In case you need to customize the link even further, you can use the useLink hook to create your own implementation.

Data Attributes

Link has the following attributes on the base element:

  • data-focus: When the link is being focused. Based on useFocusRing
  • data-focus-visible: When the link is being focused with the keyboard. Based on useFocusRing
  • data-disabled: When the link is disabled. Based on isDisabled prop.

Accessibility

  • Support for mouse, touch, and keyboard interactions.
  • Support for navigation links via <a> elements or custom element types via ARIA.
  • Support for disabled links.
  • Keyboard users may activate links using the Enter key.

API

PropTypeDefault
size
sm | md | lg
"md"
color
foreground | primary | secondary | success | warning | danger
"primary"
underline
none | hover | always | active | focus
"none"
href
string
target
HTMLAttributeAnchorTarget
rel
string
download
boolean | string
ping
string
referrerPolicy
HTMLAttributeReferrerPolicy
isExternal
boolean
false
showAnchorIcon
boolean
false
anchorIcon
ReactNode
isBlock
boolean
false
isDisabled
boolean
false
disableAnimation
boolean
false
PropTypeDefault
onPress
(e: PressEvent) => void
onPressStart
(e: PressEvent) => void
onPressEnd
(e: PressEvent) => void
onPressChange
(isPressed: boolean) => void
onPressUp
(e: PressEvent) => void
onKeyDown
(e: KeyboardEvent) => void
onKeyUp
(e: KeyboardEvent) => void
onClick
MouseEventHandler