Skip to content

Link

Takes the user to another page or section. Primary, neutral and on-colour, two sizes, inline and external.

Version 0.2.0 ·

Styles and sizes
Direction
Theme
Viewport

Installation

bunx --bun shadcn@latest add @dga/link

Usage

app/page.tsx
tsx
import NextLink from "next/link";
import { Link } from "@/components/ui/link";

<Link render={<NextLink href="/services" />}>الخدمات</Link>

Without render, Link renders a plain <a>. Use a Button for actions.

Anatomy

  • Root: an <a>, or any element through render.
  • Label: the link text.
  • External icon (external links): mirrored in RTL.

Examples

Inline

Inside running text, set inline. Inline links are always underlined, so they can be told apart without colour (WCAG 1.4.1).

Inline

External

external opens a new tab with rel="noopener noreferrer", adds the external-link icon and tells screen readers. Translate the hint with externalLabel:

page.tsx
tsx
<Link href="https://dga.gov.sa" external externalLabel="(يفتح في علامة تبويب جديدة)">
  هيئة الحكومة الرقمية
</Link>

RTL

Text and the external-link icon follow the reading direction; the icon is mirrored in Arabic.

LTR (English)
RTL (Arabic)

Accessibility

KeyAction
TabMoves focus to the link.
EnterFollows it.
  • A real <a href>: works with the keyboard, middle-click and "open in new tab".
  • Visited links change colour (link-primary-visited). Hover and pressed also underline.
  • Focus ring on :focus-visible only: 2px border-black, 2px offset, white on brand fills.
  • A disabled link has no href, cannot be focused and is announced as disabled.

API Reference

A text link in the DGA link colours. Works with Next.js `Link` through `render`.

Link props
PropTypeDefault
ReactElement | function

Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render.

No default
"on-color" | "primary" | "neutral"

Colour. `on-color` is for links on brand fills.

"primary"
"sm" | "md"

Text size: `sm` 14px, `md` 16px.

"md"
boolean

Always underlined, for links inside running text (WCAG 1.4.1).

false
boolean

Opens in a new tab, adds rel="noopener noreferrer" and an external-link icon.

false
string

Screen-reader text added to external links. Translate it on Arabic pages.

"(opens in a new tab)"
string

Destination.

No default
boolean

Renders without an href, with aria-disabled.

false

Also accepts the props of the element it renders.

Deviations from DGA

ChangeReason
--link-oncolor-hovered (light) and 5 moreTranslucent white (60–90%) on the brand fill is 2.73–4.21:1. On-colour links stay white; hovered and pressed are shown by the underline.
Link: focus ring and disabledKeyboard-only focus (WCAG 2.4.7). A link without an href cannot be followed or focused.
Link: externalWCAG 3.2.5: warn before opening a new window.

View all 8 deviations for this component

Contrast

96 pairs checked · all pass WCAG 2.1 AAShow 18 states
Variant / stateLightDark
primary / default4.54:1 AA7.73:1 AAA
primary / hovered6.31:1 AA10.38:1 AAA
primary / pressed8.18:1 AAA13.05:1 AAA
primary / visited8.18:1 AAA13.05:1 AAA
primary / focused4.54:1 AA7.73:1 AAA
primary / focus ring17.31:1 3:117.49:1 3:1
neutral / default9.73:1 AAA12.04:1 AAA
neutral / hovered4.57:1 AA6.32:1 AA
neutral / pressed7.04:1 AAA6.32:1 AA
neutral / visited8.18:1 AAA13.05:1 AAA
neutral / focused9.73:1 AAA12.04:1 AAA
neutral / focus ring17.31:1 3:117.49:1 3:1
on-color / default4.74:1 AA4.74:1 AA
on-color / hovered4.74:1 AA4.74:1 AA
on-color / pressed4.74:1 AA4.74:1 AA
on-color / visited4.74:1 AA4.74:1 AA
on-color / focused4.74:1 AA4.74:1 AA
on-color / focus ring4.74:1 3:14.74:1 3:1

Text needs 4.5:1, icons and focus rings 3:1. Disabled states are exempt. Full contrast report