Skip to content
flyingsalmon

Text link

An anchor for a sentence or a line of UI copy that takes its size and weight from the text around it and keeps its underline.

Every itinerary starts from a template, and the one Brian Nguyen reaches for most is the three days in Kyoto walking route that begins at Fushimi Inari, which fits temples, tea, and a river walk into a weekend.

Installation

npx shadcn@latest add @flyingsalmon/text-link

Usage

import { TextLink } from '@/components/ui/text-link'

export function TextLinkUsage() {
  return (
    <p>
      Read the <TextLink href="/trips/kyoto">Kyoto itinerary</TextLink>.
    </p>
  )
}

Examples

Inside muted text

In an alert, a field description, or any muted block, the link keeps the foreground colour while its surroundings stay muted, so it reads one step stronger than the copy around it.

Two travellers have no passport on file
Add their documents on the travellers page before you book.

On a card

Tab to the link. The focus ring's gap paints the page colour, so on a card pass focus-visible:ring-offset-card and the gap matches the surface.

Weekend in Kyoto

Three days, ten stops, and one very long river walk at dusk.

Guidelines

When to use

  • To navigate from inside a sentence or a line of copy: to another page, another site, or a place on the same page.

When not to use

  • Use Button to send, save, open, or retry. A link navigates and a button acts. For an action inside a sentence, such as "Didn’t get the code? Resend", place the button inline.
  • Use Breadcrumb for the levels of a trail, which read as links by position and draw no underline.
  • Use Sidebar for navigation items, which read as links by position and draw no underline.

Do and don’t

  • Do
    Put the way out of a problem as a link in the sentence that describes it, such as “Add their passport details” inside a warning.The path forward sits next to the problem, where the reader’s attention already is.
  • Don’t
    Write “click here” or “learn more” as the link text.The words name where the traveller ends up or the next step, so the link still makes sense when read on its own.
  • Do
    Let the link take the size and weight of the sentence it sits in.It is part of the sentence and breaks across lines with the text around it.
  • Do
    Keep the link in the foreground colour inside muted copy.It stands one step stronger than the text around it, and that contrast is what marks it as a way to go.
  • Don’t
    Disable a text link.An anchor that cannot navigate is plain text, so render text.
  • Don’t
    Put a text link inside a card or table link that already covers the surface.The surface is the hit target, and an underline inside it competes with the title.

Accessibility

KeyDescription
TabMoves focus to the link.
EnterFollows the link.

It is a native anchor, so it keeps the browser’s behaviour for context menus and new tabs. The underline never leaves, so the link is never told apart by colour alone. Tab to a link that wraps across lines and the focus ring closes around each line fragment separately.

API

TextLink

Also takes every <a> attribute. There is no external prop, no size, and no variant.

PropTypeDefaultDescription
hrefstring–Where the link goes. Required unless asChild passes an element that supplies its own: an anchor that navigates nowhere is an action, and an action is a button.
asChildbooleanfalseRenders its single child, such as your router’s link, with the text link styling.

  • Button

    The control for an action, where a link navigates.
  • Breadcrumb

    Links back up the hierarchy.
  • Alert

    A common home for a link in muted copy.
  • Accessibility

    Focus and contrast across the registry.