Link

Navigation, inside text or on its own. For an action, use a Button; for a link that looks like a button, use .hbutton on the <a>.

Installation

bun add @harmo-ui/css @harmo-ui/react

Usage

import { Link } from "@harmo-ui/react";

<Link href="/settings">Settings</Link>

Examples

This site is using your theme

Standalone

On its own, a link needs no underline: its color and place set it apart. It takes the font of the text around it.

<>
  <Link href="/settings">Settings</Link>
  <Link href="/campaigns">All campaigns</Link>
  <Link href="/help">Help center</Link>
</>

In running text

Inside a sentence, color is the only cue, and the link purple is 2.03:1 against body text, short of WCAG 1.4.1. data-underlined adds the underline that tells a link apart.

Contacts who unsubscribe stop receiving campaigns. Read the unsubscribe policy for the details.

<p>
  Contacts who unsubscribe stop receiving campaigns. Read the{" "}
  <Link underlined href="/help/unsubscribes">
    unsubscribe policy
  </Link>{" "}
  for the details.
</p>

Visited

data-visited turns a link dark purple once its page is in the browser's history. Both links carry it; the first stands in for a page you have opened.

<>
  <Link visited href="/help/getting-started">
    Getting started
  </Link>
  <Link visited href="/release-notes">
    Release notes
  </Link>
</>

With an icon

A .hicon child lines the icon up with the text, --harmo-icon-gap apart. Put icons after the text: the link keeps the text's baseline, so an icon first would sit slightly high. A ChevronToArrow turns into an arrow on hover or keyboard focus.

<>
  <Link href="/settings">
    Settings
    <Chevron />
  </Link>
  <Link href="/reports">
    All reports
    <ChevronToArrow />
  </Link>
</>

Right to left

The same links in Arabic. The ChevronToArrow follows the reading direction and points left.

<>
  <Link href="/settings">الإعدادات</Link>
  <Link href="/reports">
    كل التقارير
    <ChevronToArrow />
  </Link>
</>

Long text

In a narrow container, drawn dashed here, an icon link wraps its text and keeps the icon beside it.

<Link href="/help/automations">
  Set up your first automated campaign
  <ChevronToArrow />
</Link>

API reference

React

<Link> renders the link, through HarmoProvider's linkComponent (an <a> by default). Put an icon after the text, as a child. Other props are the link's attributes; href is required.

PropEffect
underlinedAdds the underline, for a link in running text
visitedTurns it dark purple once its page is in the browser's history

HTML

An <a class="hlink" href="…">, with an optional direct .hicon after the text. Load link.css; chevron.css or chevron-to-arrow.css for an icon. It needs no script.

HookEffect
A direct .hiconinline-flex, with --harmo-icon-gap (6px) between the text and the icon
data-underlinedUnderlined, 0.2em below the text, for links in running text; off by default
data-visitedVisited links turn --harmo-link-visited-color-text (dark purple), without a color transition; off by default

See Link's full contract.

Accessibility

Links with an icon and breadcrumb links are identifiable without an underline, but inside a sentence color is the only cue, and purple is 2.03:1 against body text: below what WCAG 1.4.1 asks (an underline, or 3:1 plus a hover cue). Put data-underlined on links in running text to meet it; standalone and icon links can stay ununderlined. Visited links look unvisited unless the link carries data-visited.