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-linkUsage
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.
External link
Whether a link opens a new tab is your app's policy, so you pass target and rel yourself and place the icon as a child. The icon scales with the sentence.
Japan’s rail passes are explained in the rail pass guide, which lists every regional option.
Router link
asChild hands the styling to the element you pass, so your router renders the anchor and client-side navigation keeps working.
See every day of the route on the trip overview.
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
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
- DoPut 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’tWrite “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.
- DoLet 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.
- DoKeep 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’tDisable a text link.An anchor that cannot navigate is plain text, so render text.
- Don’tPut 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
| Key | Description |
|---|---|
| Tab | Moves focus to the link. |
| Enter | Follows 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.
| Prop | Type | Default | Description |
|---|---|---|---|
| href | string | – | 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. |
| asChild | boolean | false | Renders its single child, such as your router’s link, with the text link styling. |